jakartaee / mail-api

Jakarta Mail Specification project
https://jakartaee.github.io/mail-api
Other
244 stars 101 forks source link

Java Mail Oauth for gmail: require full mail scope for sending emails only #584

Open javaone199 opened 2 years ago

javaone199 commented 2 years ago

JavaMail oauth requires full mail scope for sending email via gmail.

Used scope "https://www.googleapis.com/auth/gmail.send" for authorization. and then got refresh and access token.

Java mail:

transport.connect(host, port, username, access_token);

Got error:

Caused by: jakarta.mail.AuthenticationFailedException: OAUTH2 asked for more at com.sun.mail.smtp.SMTPTransport$OAuth2Authenticator.doAuth(SMTPTransport.java:1121) at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:924)

After changing scope to "https://mail.google.com/" for authorization, it works. But this scope will authorize

send, read, delete all emails.

This scope is too much, no difference from password authentication.

javaone199 commented 2 years ago

Jakarta mail version: 2.0.1

Ben-Liao commented 2 years ago

Hi, is this issue going to adjust?