2013-05-09 69 views
0

我需要將消息附件存儲到本地硬盤驅動器..是否有任何解決方法實現此目的?我正在使用S22.Imap dllS22.Imap保存消息附件到本地硬盤

using (ImapClient Client = new ImapClient("imap.gmail.com", 993, 
      "[email protected]", "xxxxxxxxxx", S22.Imap.AuthMethod.Login, true)) 
      { 
       uint[] uids = Client.Search(
        SearchCondition.From("[email protected]").And(
        SearchCondition.SentSince(new DateTime(2013, 5, 8))).And(
        SearchCondition.SentBefore(new DateTime(2013, 5, 9))) 
       ); 

       MailMessage[] messages = Client.GetMessages(uids, 
        (Bodypart part) => 
        { 
         // We're only interested in attachments 
         if (part.Disposition.Type == ContentDispositionType.Attachment) 
         { 
          Int64 TwoMegabytes = (1024 * 1024 * 2); 
          if (part.Size > TwoMegabytes) 
          { 
           // Don't download this attachment 
           return false; 
          } 
         } 

         // fetch MIME part and include it in the returned MailMessage instance 
         return true; 
        } 
       ); 
       string attachment_name; 
       if (messages[0].Attachments.Count > 0) 
       { 




       } 
      } 

沒有將這些附件保存到本地驅動器的內置方法。此外,這可以通過S22.Mail.dll庫實現,但我無法找到這個庫。有人可以提供我的解決方案嗎? 這是S22.Mail源代碼https://github.com/smiley22/S22.Mail的鏈接。

回答

0

有/是一些問題庫,我試圖在Pull #42修復(在寫這一點,還沒有被合併 - 你可能會想拉一個分支代替)

Message.Attachments然後遍歷代替的部分。 Net.Mail.Attachment.ContentStream會給你一個流,你可以複製到一個文件。 要檢查大小,請使用ContentStream.Length

如何可以節省的流量已被深入涵蓋在:How do I save a stream to a file in C#?

+0

Hey Nikize。感謝您的迴應。不幸的是,我不能測試這個,因爲我沒有在那個特定的項目上工作。不知何故,我已經使用了一些其他庫來實現這個功能。謝謝。 – 2013-08-26 06:40:19

相關問題