We are thinking about using Aspose.Email (EWS) v19.8.0 for a .NET solution that should read emails from an Exchange server.
Given Microsoft’s announcement on upcoming changes to Exchange Web Services (EWS) API for Office 365:
It would seem wiser to consider using OAuth instead of Basic Authentication? But how exactily do you do that with Aspose.Email?
I have been using this guide to connect to Microsoft’s API using OAuth.
“Microsoft : Authenticate an EWS application by using OAuth (and how to register application in Microsoft Azure.)”
It takes these parameters to work:
appId : Guid from Microsoft Azure after registering my App
tenantId : Guid from Microsoft Azure after registering my App
ewsScopes : “https://outlook.office.com/EWS.AccessAsUser.All”
mailboxUri : “https://outlook.office365.com/ews/exchange.asmx”
The only documentation I have been able to find on Aspose.Email and OAuth is here:
Aspose.Email – OAuth Support for EWS with Office 365
Your code example looks like this:
string authority = ConfigurationManager.AppSettings[“authority”];
string clientID = ConfigurationManager.AppSettings[“clientID”];
Uri clientAppUri = new Uri(ConfigurationManager.AppSettings[“clientAppUri”]);
string resource = ConfigurationManager.AppSettings[“resource”];
AuthenticationContext authenticationContext = new AuthenticationContext(authority, false);
AuthenticationResult authenticationResult = authenticationContext.AcquireToken(resource, clientID, clientAppUri);
OAuthNetworkCredential oAuthCredential = new OAuthNetworkCredential(authenticationResult.AccessToken);
using (IEWSClient client = EWSClient.GetEWSClient(resource + “ews/exchange.asmx”, oAuthCredential))
ExchangeMessageInfoCollection messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri);
What are the correct values for the parameters and where do I get/find them? (I assume some of them are equal to the ones used with Microsoft’s API?)
I have not been able to get it to work. Can you give me a .NET code example with some real example values?