OAuth Auth for Gmail(and OAuth token based mail services) to avoid "less secure apps"
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.
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:
We are all looking forward to this enhancement.
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