Link to home
Start Free TrialLog in
Avatar of barkome
barkomeFlag for Canada

asked on

S22.Imap dll save attached files to designated directory

Hello

Im S22.Imap dll with the following C# code below to save attached files to emails within a mailbox.

Does anyone know I can save the attached files to a directory?
Source of the code is : https://github.com/smiley22/S22.Imap/blob/master/Examples.md#7

namespace S22
{

    class Program
    {
        static void Main(string[] args)
        {
            using (ImapClient Client = new ImapClient("server", port, @"domain\user_id\mailbox", "Password", AuthMethod.Login, false))
            {
                // This returns all messages sent since August 23rd 2016.
                IEnumerable<uint> uids = Client.Search(SearchCondition.SentSince(new DateTime(2016, 8, 26)));
                // The expression will be evaluated for every MIME part
                // of every mail message in the uids collection.
                IEnumerable<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;
                    }
                );
            }
        }
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of louisfr
louisfr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial