+1 vote

Hello,

I am using Mail.dll for email functionality like download emails. I want to upload Draft and Deleted emails of my application. I have referred following links :
https://www.limilabs.com/blog/send-email-with-attachment
https://www.limilabs.com/blog/replace-attachments-in-email-message
https://www.limilabs.com/blog/uploading-emails-using-imap

Can I use the same code for Exchange Server Emails? Please suggest me so I can decide to use Mail.dll for Exchange Server too.

by (3.0k points)

1 Answer

0 votes

Exchange fully supports IMAP protocol, so it of course allow email upload via IMAP. Remember to enable IMAP in Exchange.

The samples you mentioned all apply to Exchange server as well.

Code for uploading emails is dead simple:

using (Imap imap = new Imap())
{
    imap.Connect("imap.example.com");    // or ConnectSSL for SSL
    imap.UseBestLogin("user", "password");

    CommonFolders folders = new CommonFolders(imap.GetFolders());

    imap.UploadMessage(folders.Drafts, email);

    imap.Close();
}

I want to upload [...] Deleted emails of my application

Usually it is not needed as most servers move emails you delete to Deleted folder automatically.

Also remember, that moving an email between folders (Imap.MoveByUID) is much faster that downloading, deleting, and uploading.

by (297k points)
...