Problem connecting to smtp.outlook.com using OAuth and MASL4J

Martin Gilchrist 0 Reputation points
2024-10-15T04:25:38.68+00:00

In my Java application I have been able to send an email using just my outlook.com address to connect to smtp.office365.com. Recently this stopped working because Microsoft have disabled basic authentication, and support only OAuth. So I have tried to update my code to use the msal4j library, and have made some progress, but am not yet at the point when I can send a message using OAuth. Here's what I have done:

  1. Logged in to entra.microsoft.com and registered an app. I have generated a client secret for the app.
  2. In the registered app, I have granted it the SMTP.Send permission.
  3. I have updated my Java application as follows:
         `/* Set up connection to generate access token */`
    

String authority = "https://login.microsoftonline.com/" + myTenantId;

String applicationIDURI = myApplicationIDURI (from the Entra UI);

` Set

Outlook | Windows | Classic Outlook for Windows | For business
Community Center | Not monitored
0 comments No comments
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.