Lấy thông tin thư mục từ hộp thư IMAP

Aspose.Email - Lấy thông tin thư mục từ hộp thư IMAP

Lấy thông tin về các thư mục từ máy chủ IMAP rất dễ dàng với Aspose.Email. Phương thức listFolders() của ImapClient trả về một đối tượng ImapFolderInfoCollection chứa thông tin về tất cả các thư mục trên máy chủ. Duyệt qua bộ sưu tập này và lấy thông tin về từng thư mục trong một vòng lặp. Phương thức này được nạp chồng. Bạn có thể truyền tên thư mục làm tham số để nhận danh sách các thư mục con.

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());

}

Tải mã đang chạy

Tải Lấy thông tin thư mục từ hộp thư IMAP từ bất kỳ một trong các trang mã nguồn xã hội được đề cập dưới đây: