Access to email exchange from c#

To use this code, you need to installhttp://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=c3342fb3-fbcc-4127-becf-872c746840e1 , this will create a dll, that you need to import to the project

 ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

 service.Credentials = new NetworkCredential(user, password, domain);

 service.Url = new Uri("https://domain/EWS/Exchange.asmx");

 Mailbox mb = new Mailbox(email_to_access);
 FolderId fid1 = new FolderId(WellKnownFolderName.Inbox, mb);

 //reads the emails
 FindItemsResults <Item> findResults = service.FindItems(fid1, new ItemView(50));


 foreach (Item item in findResults.Items)
 {
  item.Load();
  EmailMessage m = (EmailMessage)item;
  if (!m.IsRead)
  {
   //Set Isread.
   m.IsRead = true;
   m.Update(ConflictResolutionMode.AutoResolve);
  }
 }

0 comentários:

Enviar um comentário