简体   繁体   English

使用Mailkit使用IMAP保存附件

[英]Using Mailkit to save attachments using IMAP

I have a need to find a particular email on a Google IMAP server and then save the attachments from the email. 我需要在Google IMAP服务器上找到特定的电子邮件,然后保存电子邮件中的附件。 I think I have it all figured out except for the part of determining what the file name is of the attachment. 我想我已经弄明白了,除了确定附件的文件名是什么的部分。

Below is my code so far, I am hoping that someone can point me in the right direction to determine the file name. 下面是我的代码到目前为止,我希望有人可以指出我正确的方向来确定文件名。

I have Googled and SO'd but have not been able to find something using the attachment approach. 我用Googled和SO'd但是找不到使用附件方法的东西。

internal class MailKitHelper
{
    private void SaveAttachementsForMessage(string aMessageId)
    {
        ImapClient imapClient = new ImapClient();
        imapClient.Connect("imap.google.com", 993, SecureSocketOptions.Auto);
        imapClient.Authenticate("xxxx", "xxxx");

        HeaderSearchQuery searchCondition = SearchQuery.HeaderContains("Message-Id", aMessageId);
        imapClient.Inbox.Open(FolderAccess.ReadOnly);
        IList<UniqueId> ids = imapClient.Inbox.Search(searchCondition);

        foreach (UniqueId uniqueId in ids)
        {
            MimeMessage message = imapClient.Inbox.GetMessage(uniqueId);

            foreach (MimeEntity attachment in message.Attachments)
            {
                attachment.WriteTo("WhatIsTheFileName"); //How do I determine the file name
            }
        }
    }
}

最终获胜者是.....

attachment.ContentDisposition.FileName

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM