AE.Net.Mail Imap部分提取

时间:2012-06-06 20:29:22

标签: c# imap gmail-imap

我正在使用C#和AE.Net.Mail库从Gmail中提取文件。我在使用大型zip文件时遇到了问题。

使用Java描述和解决了同样的问题:JavaMail BaseEncode64 Error

有谁知道如何使用C#和AE.Net.Mail库设置部分提取标志?

1 个答案:

答案 0 :(得分:1)

一起去(或看看)S22.Imap。这是一个AE.Net.Mail记录了一些额外的东西。

示例:仅在小于2兆字节的情况下下载附件

using System;
using S22.Imap;

namespace Test {
class Program {
    static void Main(string[] args)
    {
        using (ImapClient Client = new ImapClient("imap.gmail.com", 993,
         "username", "password", Authmethod.Login, true))
        {
            // This returns all messages sent since August 23rd 2012
            uint[] uids = Client.Search(
                SearchCondition.SentSince( new DateTime(2012, 8, 23) )
            );

            // Our lambda expression will be evaluated for every MIME part
            // of every mail message in the uids array
            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;
                }
            );
        }
    }
}
}