Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection to Office 365 by EWS API

Tags:

I am using EWS API in my console application to process mailbox items and my connection script looks like

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); service.UseDefaultCredentials = true; service.AutodiscoverUrl("[email protected]"); 

But i found that my email account was moved to Office 365 cloud. How should i change the authentication ?

i found EWS service url

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

but i dont know how to use it.

Thank you

like image 867
Muflix Avatar asked Sep 02 '15 14:09

Muflix


People also ask

Does Office 365 use EWS?

EWS is a comprehensive service that your applications can use to access almost all the information stored in an Exchange Online, Exchange Online as part of Office 365, or Exchange on-premises mailbox.


1 Answers

You can use the code below to connect to the EWS on office 365:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);  service.Credentials = new WebCredentials("[email protected]", "password"); service.AutodiscoverUrl("[email protected]", RedirectionUrlValidationCallback); 

You need define one callback function for the AutodiscoveryUrl function, like this:

private static bool RedirectionUrlValidationCallback(string redirectionUrl) {     // The default for the validation callback is to reject the URL.     bool result = false;      Uri redirectionUri = new Uri(redirectionUrl);      // Validate the contents of the redirection URL. In this simple validation     // callback, the redirection URL is considered valid if it is using HTTPS     // to encrypt the authentication credentials.      if (redirectionUri.Scheme == "https")     {         result = true;     }     return result; } 
like image 142
Matt Avatar answered Nov 14 '22 15:11

Matt