IMAP メールボックスからフォルダー情報を取得

Aspose.Email - IMAP メールボックスからフォルダー情報を取得

Aspose.Email を使用すると、IMAP サーバーからフォルダー情報を取得するのは非常に簡単です。ImapClient の listFolders() メソッドは、サーバー上のすべてのフォルダー情報を含む 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 をダウンロードしてください: