简体   繁体   中英

AE.Net.Mail Imap partial fetch

I'm using C# and the AE.Net.Mail library to pull files from Gmail. I'm having problems with large zip files.

The same problem is described and resolved here with Java: JavaMail BaseEncode64 Error

Does anyone know how to set partial fetch flag with C# and the AE.Net.Mail library?

Go with (or take a look at) S22.Imap . It's an AE.Net.Mail documented with some extras.

From examples: Download attachments only if they are smaller than 2 Megabytes

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;
                }
            );
        }
    }
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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