Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jakarta.ee-community] OAuth2 question

Ralph,

Thank you for the reply.  

Unfortunately I'm using SMTP so the implementation is different. 


Further, there is a jakarta.mail.Authenticator class and I'm using it. 

See the code below and https://jakarta.ee/specifications/mail/2.1/apidocs/jakarta.mail/jakarta/mail/authenticator


Cheers,

    Todd



On 9/19/25 4:20 AM, Ralph Soika via jakarta.ee-community wrote:

Hi Todd,

I think what you are looking for is an OAuth-Authenticator class. I don't think this is part of the Jakarta EE Stack.

I have written such an authenticator for Outlook by myself. You can find the open source implementation here:

https://github.com/imixs/imixs-data/blob/main/imixs-data-importer/src/main/java/org/imixs/workflow/importer/mail/IMAPOutlookAuthenticator.java


I am not sure if it is possible to implement a generic OAuth Adapter for IMAP. But maybe this helps you out for the moment...


Best regards
Ralph


On 19.09.25 03:33, Todd Hill via jakarta.ee-community wrote:

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

	transport.connect();

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/



_______________________________________________
jakarta.ee-community mailing list
jakarta.ee-community@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jakarta.ee-community
--

Imixs Software Solutions GmbH
Web: www.imixs.com Phone: +49 (0)89-452136 16
Timezone: Europe/Berlin - CET/CEST
Office: Frei-Otto-Str. 4, 80797 München
Registergericht: Amtsgericht München, HRB 136045
Geschäftsführer: Gaby Heinle u. Ralph Soika

Imixs is an open source company, read more: www.imixs.org


_______________________________________________
jakarta.ee-community mailing list
jakarta.ee-community@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jakarta.ee-community

Back to the top