+1 vote

At a time all the attachments should be download only for a particular subject which I can hard code.

by
edited by

1 Answer

0 votes

Use Imap.Search method and appropriate expressions to build a search query and filter email messages.

Then you should download messages from IMAP server, parse them using MailBuilder class and use IMail.Attachments to access email attachments.

Here's the sample code:

using(Imap imap = new Imap())
{
    imap.ConnectSSL("imap.example.org");
    imap.UseBestLogin("user@example.org", "password");

    imap.SelectInbox();

    List<long> uids = imap.Search(
        Expression.Subject("The subject"));

    foreach (long uid in uids)
    {
        var eml = imap.GetMessageByUID(uid);
        IMail email = new MailBuilder().CreateFromEml(eml);
        foreach (MimeData attachment in email.Attachments)
        {
            string fileName = attachment.FileName;
            byte[] data = attachment.Data;
        }
    }
    imap.Close();
}

If you only need to download attachments you can consider downloading only parts of email message.

by (301k points)
...