【发布时间】:2017-04-10 19:00:48
【问题描述】:
我在网上查看了其他示例,但我无法弄清楚如何从 MimeMessage 对象下载和存储所有附件。 我确实查看了 WriteTo(),但我无法让它工作。 也想知道附件是否会按照原文件名保存,并在邮件中输入。 这是我目前所拥有的:
using (var client = new ImapClient())
{
client.Connect(Constant.GoogleImapHost, Constant.ImapPort, SecureSocketOptions.SslOnConnect);
client.AuthenticationMechanisms.Remove(Constant.GoogleOAuth);
client.Authenticate(Constant.GoogleUserName, Constant.GenericPassword);
if (client.IsConnected == true)
{
FolderAccess inboxAccess = client.Inbox.Open(FolderAccess.ReadWrite);
IMailFolder inboxFolder = client.GetFolder(Constant.InboxFolder);
IList<UniqueId> uids = client.Inbox.Search(SearchQuery.All);
if (inboxFolder != null & inboxFolder.Unread > 0)
{
foreach (UniqueId msgId in uids)
{
MimeMessage message = inboxFolder.GetMessage(msgId);
foreach (MimeEntity attachment in message.Attachments)
{
//need to save all the attachments locally
}
}
}
}
}
【问题讨论】:
-
您需要对文件名进行一些清理。检查欺骗,删除坏字符...