play-mailer icon indicating copy to clipboard operation
play-mailer copied to clipboard

OAuth Auth for Gmail(and OAuth token based mail services) to avoid "less secure apps"

Open Jacke opened this issue 9 years ago • 3 comments

Hi. Is there have plans for developing https://java.net/projects/javamail/pages/OAuth2 this sort of auth? If anybody needs this feature I can start implementing it to play mailer on next week.

Jacke avatar Mar 28 '16 05:03 Jacke

Hello @Jacke, this would be a great addition!

Behind the scene, play mailer plugin is using commons-email library which relies on Java mail 1.5.2. If I read correctly OAuth2 Authentication is only available from Java mail 1.5.5 and later ?

I think you should open an issue to commons-email library to ask for an upgrade from 1.5.2 to 1.5.5: commons-email issue tracker

In the mean time you can experiment by excluding Java mail 1.5.2 dependency and adding explicitly a dependency on Java mail 1.5.5 in build.sbt

If you need help, feel free to ask :smile:

ggrossetie avatar Mar 28 '16 09:03 ggrossetie

We are all looking forward to this enhancement.

litts avatar Mar 31 '16 09:03 litts

I think you can already do it by setting a system property: System.setProperty("mail.smtp.auth.mechanisms", "XOAUTH2");. The mail session is using system properties so this code is equivalent to:

Properties props = new Properties();
props.put("mail.smtp.auth.mechanisms", "XOAUTH2");
Session session = Session.getInstance(props);

As far as I know, only this property is required to switch to an OAuth2 authentication. I've also open on Commons Email because I think it's better to have a dedicated API to set the authentication mechanism: https://issues.apache.org/jira/browse/EMAIL-163

@litts @Jacke Could you please give it a try ? thanks

ggrossetie avatar Apr 12 '16 21:04 ggrossetie