2013-05-09 63 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

相关问题