[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[jakarta.ee-community] OAuth2 question
|
Group,
Forgive me if this is not the proper place to ask an
implementation question.
I'm running out of options to resolve this problem after a month
of trying with different email providers.
Am trying to implement Jakarta Mail 2.0.1 to send notification
emails from my public app.
Want to support a variety of email providers including Apple,
GMail, Outlook and Zoho.
Have it working to retrieve an access_token for Gmail,
Outlook and Zoho so far.
However, when it gets to
Jakarta Mail fails with either "OAUTH2 asked for more" for GMail
or "535 5.7.3 Authentication unsuccessful".
The relevant code:
props.put("mail.smtp.auth.mechanisms", "XOAUTH2");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
props.put("mail.smtp.auth.login.disable", "true");
props.put("mail.smtp.auth.plain.disable", "true");
props.put("mail.smtp.auth.xoauth2.disable", "false");
props.put("mail.debug", "true"); // For debugging
props.put("mail.debug.auth", "true"); // For debugging
Session session = Session.getInstance(props, new Authenticator()
{
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
if (tool.getAuthMethod().equalsIgnoreCase("oauth2"))
return new PasswordAuthentication(tool.getUsername(), tool.getAccessToken());
else // Plain
return new PasswordAuthentication(tool.getUsername(), tool.getPassword());
}
});
session.setDebug(true);
Transport transport = session.getTransport("smtp");
transport.connect();
For Outlook the log shows:
DEBUG SMTP: protocolConnect login, host=smtp-mail.outlook.com,
user=rockney8588@xxxxxxxxxxx, password=<non-null>
DEBUG SMTP: Attempt to authenticate using mechanisms: XOAUTH2
DEBUG SMTP: Using mechanism XOAUTH2
AUTH XOAUTH2 <long token>
535 5.7.3 Authentication unsuccessful
[CY8PR02CA0006.namprd02.prod.outlook.com 2025-09-19T00:24:13.488Z
08DDF5EB7845EC97]
ERROR 09/18/2025 18:24:13.581
jakarta.mail.AuthenticationFailedException: 535 5.7.3
Authentication unsuccessful
[CY8PR02CA0006.namprd02.prod.outlook.com 2025-09-19T00:24:13.488Z
08DDF5EB7845EC97]
In the case of Outlook:
- 2FA is disabled for the rockney8588@xxxxxxxxx account.
- The domain elsnavigator.com has been verified.
- The Microsoft app registration API permissions (scopes):

- The Authentications are set as:
The configuration and results for GMail and Zoho can be provided
if requested.
See also:
https://stackoverflow.com/questions/79752745/how-to-send-email-through-gmail-account-using-jakarta-mail-2-0-1-oauth2-smtp-a
Have not been able to find the correct combination for Jakarta
Mail OAuth2 in Gmail, Outlook or Zoho.
Any guidance would be very much appreciated.
Regards,
Todd Hill
https://www.elsnavigator.com/