使用 IMAP 处理邮件附件
Contents
[
Hide
]
使用 IMAP 客户端列出邮件附件
要获取附件的名称、大小等信息而不下载附件数据,请使用以下 API 功能:
- ImapAttachmentInfo - 表示附件信息。
- ImapAttachmentInfoCollection - 表示 ImapAttachmentInfo 的集合。
- listAttachments(int sequenceNumber) - 获取邮件中每个附件的信息。
以下代码示例展示了如何使用 IMAP 客户端从服务器检索邮件及其附件的信息,然后显示每封邮件的附件详情。它允许您使用 IMAP 协议访问和处理邮件附件。
ImapMessageInfoCollection messageInfoCollection = imapClient.listMessages();
for (ImapMessageInfo message : messageInfoCollection) {
ImapAttachmentInfoCollection attachmentInfoCollection =
imapClient.listAttachments(message.getSequenceNumber());
for (ImapAttachmentInfo attachmentInfo : attachmentInfoCollection) {
System.out.println(
"Attachment: " + attachmentInfo.getName() + " (size: " + attachmentInfo.getSize() + ")");
}
}