簡體   English   中英

使用Mailkit使用IMAP保存附件

[英]Using Mailkit to save attachments using IMAP

我需要在Google IMAP服務器上找到特定的電子郵件,然后保存電子郵件中的附件。 我想我已經弄明白了,除了確定附件的文件名是什么的部分。

下面是我的代碼到目前為止,我希望有人可以指出我正確的方向來確定文件名。

我用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