Search code examples
c#emailoutlookoutlook-2007

How to delete an email from Outlook using C#?


I can successfully retrieve and read emails from Outlook using the following code. How can I delete an email from Outlook? I have tried several ways but couldn't get it to work.

var svc = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
svc.Credentials = CredentialCache.DefaultNetworkCredentials;
svc.AutodiscoverUrl(emailAddress);
EmailMessage email = EmailMessage.Bind(svc, emailMessage.Id, props);

Solution

  • I'm not sure (ie, may be proven incorrect) that you can delete messages using this API. The MSDN article for Microsoft.Exchange.Data.Transport.Email Namespace says this:

    The Microsoft.Exchange.Data.Transport.Email namespace contains types that support creating, reading, writing, and modifying e-mail message.

    And further inspection of the members available on the EmailMessage class suggest you can access various properties, but there's no "delete" operation/method available.

    Depending on your scenario, you might have better luck using a tool like Outlook Redemption which will allow low-level programmatic access to Outlook and/or Exchange (but may not be appropriate if you need to go via exchange web services).