Search code examples
c#exchangewebservicesexchange-server-2010

Read email content and move items between folders with Exchange 2010 and c#


I’m working on an application that must read the email content and move emails from one folder to another, these are the only two features that it must support. The mail server is Exchange 2010 and I have enough privileges to access the mailbox.

I’ve been seeing some posts about EWS Managed Code but I’m certainly lost in all this information. Can you shed some light on this and advise about the best approach to accomplish it?

Ps. Using VS 2015 and .net framework 4.5

Update: find below a quick test using the EWS Manage API

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
//This will accept all certificates, regardless of why they are invalid
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
service.Credentials = new WebCredentials("Administrator", "mypassword", "myexchangeserver.com");
service.Url = new Uri("https://myexchangeserver.com/EWS/Exchange.asmx");

EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("userid@myexchangeserver.com");
email.Subject = String.Format("HelloWorld at {0}", DateTime.Now);
email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed API.");
email.Send();

Solution

  • I’m working on an application that must read the email content and move emails from one folder

    Okay so you will need to use a Exchange Mailbox API to access Mailbox content, on Exchange 2010 the available API's that you could use to move a Message between folders would be MAPI (via the Outlook Object Model or Thirdparty library like Redemption) or Exchange Web Services (EWS). (other API's like POP,IMAP and Activesync would also work but are much harder to use).

    To work out which is the best API to use you need to consider where your application is going to run eg if you building an code that run within outlook then using the OOM. If you building an application that is going to run on the server then use EWS.

    I’ve been seeing some posts about EWS Managed Code but I’m certainly lost in all this information.

    If your going to write and EWS app then using the Managed API is the best way to go, the best place is to jump into write some actual code eg start with

    https://msdn.microsoft.com/en-us/library/office/dn567668(v=exchg.150).aspx

    then try

    https://msdn.microsoft.com/en-us/library/office/dn600291(v=exchg.150).aspx

    Cheers Glen