รับข้อมูลโฟลเดอร์จากกล่องเมล IMAP
Contents
[
Hide
]
Aspose.Email - ดึงข้อมูลโฟลเดอร์จากกล่องเมล IMAP
การดึงข้อมูลเกี่ยวกับโฟลเดอร์จากเซิร์ฟเวอร์ IMAP ทำได้อย่างง่ายดายด้วย Aspose.Email เมธอด listFolders() ของ ImapClient จะคืนอ็อบเจกต์ ImapFolderInfoCollection ที่มีข้อมูลของโฟลเดอร์ทั้งหมดบนเซิร์ฟเวอร์ สามารถวนลูปผ่านคอลเลกชันนี้เพื่อรับข้อมูลของโฟลเดอร์แต่ละรายการได้ เมธอดนี้มีการโอเวอร์โหลด คุณสามารถส่งชื่อโฟลเดอร์เป็นพารามิเตอร์เพื่อรับรายการโฟลเดอร์ย่อยได้
Java
ImapClient client = new ImapClient();
client.setHost("--server--"); //imap.secureserver.net,
client.setPort(993);
client.setUsername("--username--");
client.setPassword("--password--");
client.setSecurityOptions(SecurityOptions.Auto);
ImapFolderInfoCollection folderInfoColl = client.listFolders();
// Iterate through the collection to get folder info one by one
for (ImapFolderInfo folderInfo:folderInfoColl)
{
// Folder name
System.out.println("Folder name is: " + folderInfo.getName());
ImapFolderInfo folderExtInfo = client.listFolder(folderInfo.getName());
// New messages in the folder
System.out.println("New message count: " + folderExtInfo.getNewMessageCount());
// Check whether its read only
System.out.println("Is it readonly? " + folderExtInfo.getReadOnly());
// Total number of messages
System.out.println("Total number of messages: " + folderExtInfo.getTotalMessageCount());
}
ดาวน์โหลดโค้ดที่ทำงาน
ดาวน์โหลด Get Folders Information from IMAP Mailbox จากไซต์โซเชียลโค้ดใดก็ได้ที่ระบุด้านล่าง: