Mail

MS Exchange Server

Introduction

http://stackoverflow.com/questions/652549/read-ms-exchange-email-in-c-sharp
MAPI or CDO via a .NET interop DLL: officially unsupported by Microsoft (it will appear to work fine, but there are problems with memory leaks due to their differing memory models).
CDOEX: that only works on the Exchange server itself, not remotely; useless.
Interop: overkill.
Exchange 2003's WebDAV support: but WebDAV is complicated, .NET has poor built-in support for it, and (to add insult to injury) Exchange 2007 nearly completely drops WebDAV support.

If your organization is on Exchange 2007, however, you're in luck. Exchange 2007 comes with a SOAP-based Web service interface that finally provides a unified, language-independent way of interacting with the Exchange server. If you can make 2007+ a requirement, this is definitely the way to go.
The SOAP-based web service was wrapped by Microsoft to simplify access - it is now recommended practice to use the Exchange Web Services Managed API 1.0 SDK: msdn.microsoft.com/en-us/library/dd633710(EXCHG.80).aspx

If you need to bridge both Exchange 2003 and 2007, IMAP or POP3 is definitely the way to go.

The currently preferred (Exchange 2013 and 2016) API is EWS. It is purely HTTP based and can be accessed from any language, but there are .Net and Java specific libraries.
You can use EWSEditor to play with the API.

EWS (Exchange Web Services)

https://msdn.microsoft.com/en-us/library/dd633710%28EXCHG.80%29.aspx
https://www.emailarchitect.net/eagetmail/kb/csharp.aspx?cat=2

static string ReadInbox()
{
  StringBuilder sb = new StringBuilder();
  ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
  service.UseDefaultCredentials = true;
  service.AutodiscoverUrl("mailbox@domain.com");

  //Mailbox mb = new Mailbox(@"othermailbox@domain.com");
  Mailbox mb = new Mailbox();

  //creates a folder object that will point to inbox folder
  FolderId fid = new FolderId(WellKnownFolderName.Inbox, mb);

  //this will bind the mailbox you're looking for using your service instance
  Folder inbox = Folder.Bind(service, fid);

  //load items from mailbox inbox folder
  if (inbox != null)
  {
    FindItemsResults<Item> items = inbox.FindItems(new ItemView(100));

    foreach (var item in items)
      sb.AppendLine(item.Subject);
  }
  return sb.ToString();
}

Note: Microsoft.Exchange.WebServices.Data is a NuGet package. Install it via Tools - NuGet Package Manager - Manage NuGet Packages for Solution.

Outlook 365

Outlook Notifications REST API

Outlook Mail REST API reference
Outlook Notifications REST API

Calling REST services in C#

http://rest.elkstein.org/2008/02/using-rest-in-c-sharp.html
https://msdn.microsoft.com/en-us/library/jj819168.aspx

EWS (Exchange Web Services)

Notification subscriptions, mailbox events, and EWS in Exchange

Without Exchange / Outlook

https://stackoverflow.com/questions/9201239/send-e-mail-via-smtp-using-c-sharp

MailMessage mail = new MailMessage
{
  From = new MailAddress("you@yourcompany.com", "My name"),
  Body = message,
  Subject = "Subject",
  IsBodyHtml = false,
};
mail.To.Add(new MailAddress("user@user.com"));
SmtpClient smtp = new SmtpClient
{
  UseDefaultCredentials = false,
  Credentials = CredentialCache.DefaultNetworkCredentials
};
smtp.Send(mail);
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License