We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose Email: Issue with EWSClient

We are using EWS client to access microsoft exchange mail box. It was working fine just till last week and now getting unauthorized error(401) when trying to read inbox. Here is code which is doing connect:
EWSClient.useSAAJAPI(true);
System.setProperty(“http.auth.preference”, “NTLM”);
Authenticator.setDefault(getAuthenticator(userName,password, “”));

  IEWSClient client = EWSClient.getEWSClient(new URL(serverUrl));

AND
static Authenticator getAuthenticator(String user, String pw, String domain) {
final String username = domain + “\” + user;
final String password = pw;
//System.out.println("New Credentials " + username);
return new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}
};
}
I think, we need OAUTH2 based authorization now because basic authorization is being stopped.
Please help here OAUTH2 because we purchased Aspose Email for email support to client and now its blocker in production.

@amohan123

You can use AzureROPCTokenProvider class described in the MS Graph.

Code sample to initialize credentials:

ITokenProvider provider = new AzureROPCTokenProvider(oauth2.Tenant, oauth2.ClientId, "", oauth2.userNameEmail, oauth2.userPassword, 
    new String[] { "https://outlook.office.com/EWS.AccessAsUser.All" });
NetworkCredential credentials = new OAuthNetworkCredential(oauth2.userNameEmail, provider);

Setting the Azure “Office 365 Exchange Online”/full_access_as_app permission:

  • Application/Manage/API permissions/ + Add a permission

  • Select “APIs my organization uses” tab and search for “Office 365 Exchange Online” as shown in this image : image1.png (24.1 KB)

  • Select “Application permissions” and enable “full_access_as_app” as shown in this image : image2.png (46.7 KB)

MS Documentation link:

Access Mail Services using OAuth

Hope this helps you.