Hello and thanks for any help you can provide.
We’ve had an Coldfusion (Java) application running for over a year now that was making a connection to an exchange outlook account, retrieving messages and saving them to a file server as eml files. It was using the com.aspose.email.ImapClient class and using basic authentication. Over the past few days, we have not been able to connect, and it seems the issue is that basic authentication to azure exchange servers have been disabled and you are now required to connect using modern authentication.
I am attempting to update the code to use the following constructor but am failing. Continue to get a connection status of 16.
ImapClient(String host, int port, String username, String authInfo, boolean useOAuth, int securityOptions)
We have setup an application in azure (but to be honest, we’re not sure if we’re even doing it correctly). I’m curious if there is a thorough, guide to accomplish this transition.
Thanks for any help you can provide.
@jyoung37
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
---
title: Access Mail Services using OAuth
type: docs
weight: 190
url: /java/access-mail-services-using-oauth/
---
OAuth 2.0 support has been added to Aspose.Email and can be used to access **SMTP**, **POP3**, **IMAP** and **EWS** servers.
In general, all servers supporting **OAuth 2.0** bearer tokens can be used with Aspose.Email, but our email clients have been tested with Google mail servers and Microsoft Office 365 servers.
Access to the server from the [SmtpClient](https://reference.aspose.com/email/java/com.aspose.email/SmtpClient), [Pop3Client](https://reference.aspose.com/email/java/com.aspose.email/Pop3Client), [ImapClient](https://reference.aspose.com/email/java/com.aspose.email/ImapClient) and [EWSClient](https://reference.aspose.com/email/java/com.aspose.email/EWSClient) with OAuth may be implemented in 2 ways.
1. Provide access token directly into the constructor of email client. In this case, the user has to understand that lifetime of access tokens is limited. When the token is expired, email client can't be used to access the server.
2. Provide a custom implementation of token provider based on [ITokenProvider](https://reference.aspose.com/email/java/com.aspose.email/itokenprovider) interface into the constructor of email client. In this case, the client checks token expiration time and requests [ITokenProvider](https://reference.aspose.com/email/java/com.aspose.email/itokenprovider) for a new access token when the previous is expired. In this way, the client refreshes tokens periodically and may work with the server for unlimited time. Оften services support a simple way to refresh access tokens. For example, using refresh tokens in google services or ROPC authentication flow in Microsoft identity platform can be used for implementation token provider.
## **Configure an Account on the Appropriate Server**
The following articles help you to configure accounts to access mail services.
- For [Office 365](https://docs.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth)
This file has been truncated. show original
Hope this helps you.
@jyoung37
We suggest you please read the following article to achieve your requirement. Hope this helps you.
Using OAuth to access Mail Services