8
I’m using a API
e-mail Mail.jar
of this tutorial for sending e-mail via Java
, but I realized I have to, activate the permission for less secure apps.
There is another way to send email Java
, without having to enable this option of Gmail from less secure applications?
Try to perform SMTP connection configuration with active SSL. You can try with this link tutorial: https://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/
– Carlos Silva
There, you have to use Google’s XOAUTH2 stream. Your app directs you to Google, it logs into Google, authorizes your app, and Google redirects you back with a token. With this token, while the user does not deauthorize, your application obtains the login credentials whenever you need to access SMTP.
– Bacco
@Carlossilva the code shown in the example is what I use, then have to activate the authorization for less secure applications
– adventistaam
@Bacco I’m researching on XOAUTH2 and java
– adventistaam
@Carlos can’t help with the Java part specifically for lack of experience with the language, but the flow is basically the following: your application will direct the user to Google to get an application token on the first access, and then, whenever you use SMTP, you will use this application token to obtain a session token. This session token is used in place of the SMTP password, whenever you need it. When the session token expires, the application token allows you to request a new one. The application never expires, until the user revokes access.
– Bacco