bbottema / simple-java-mail

Simple API, Complex Emails (Jakarta Mail smtp wrapper)
http://www.simplejavamail.org
Apache License 2.0
1.23k stars 270 forks source link

Issue with Simple Java Mail: AuthenticationFailedException when using SMTP with OAuth and "Send Mail" Scope #539

Closed Venki028 closed 2 months ago

Venki028 commented 4 months ago

I am encountering an AuthenticationFailedException while using Simple Java Mail for sending emails via SMTP with OAuth authentication. Specifically, I am using the "Send Mail" scope.

Details: When attempting to send an email, the following exception is thrown: makefile

javax.mail.AuthenticationFailedException: OAUTH2 asked for more

Investigation: After some research, I discovered that expanding the scope to all scopes more than just the "Send Mail" scope seems to resolve the issue. However, according to the Gmail OAuth documentation, it is recommended to enable only the scopes that are necessary for the application.

Steps to Reproduce: Configure Simple Java Mail to use SMTP with OAuth authentication. Set the OAuth scope to only "Send Mail". Attempt to send an email.

Expected Behavior: The email should be sent successfully without requiring additional OAuth scopes.

Actual Behavior: An AuthenticationFailedException is thrown, indicating that additional OAuth scopes might be necessary.

Request for Help: I would appreciate any insights or guidance on resolving this issue while adhering to the best practices outlined in the Gmail OAuth documentation. Because in all cases, we may not use all the scopes When we apply for google Verification, they ask to use only the required scopes for your application instead of using all the scopes

Thank you for your assistance.

bbottema commented 2 months ago

OAUTH authentication is handled by the underlying mailing library implementation, Angus (previously Jakarta Mail, previously Sun JavaMail). Reading about it there, I don't see anything related to scopes, which is handled by the OAUTH provider. The problem is not with this library, which does nothing but pass on the token for authorization.