0 votes

pls share code for bulk mail download with pop3 or imap

by (930 points)

1 Answer

0 votes

Generally none of the email protocols (IMAP, POP3) allow bulk email download, that would be significantly faster than downloading emails one by one.

Basic email download sample looks like this:

using(Imap imap = new Imap())
{
    imap.Connect("imap.server.com");  // or ConnectSSL for SSL
    imap.UseBestLogin("user", "password");
    imap.SelectInbox();
    List<long> uids = imap.Search(Flag.Unseen);
    foreach (long uid in uids)
    {
        IMail email = new MailBuilder()
            .CreateFromEml(imap.GetMessageByUID(uid));
        Console.WriteLine(email.Subject);
    }
    imap.Close();
}

Please note that entire emails is downloaded, this includes all attachments.

Here's the article that shows how to download new emails using IMAP:
https://www.limilabs.com/blog/get-new-emails-using-imap

You can download most common email fields, like subject, from, to and others using following approach - it is much faster, but doesn't download entire email message and attachments:
https://www.limilabs.com/blog/get-email-information-from-imap-fast

by (301k points)
edited by
...