vertx-mail-client
vertx-mail-client copied to clipboard
GMail sending with 2FA and app password doesn't work
I have enabled 2FA and I generated app password for my account. When I supply configuration in mail-sender.zip sample app , I'm getting an error:
➜ java -jar target/mail-sender-1.0.0-SNAPSHOT-fat.jar
HTTP server started on port 8888
Oct 18, 2019 1:24:57 PM io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer
INFO: Succeeded in deploying verticle
mail sending failed! io.vertx.core.impl.NoStackTraceThrowable: AUTH XOAUTH2 failed 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials b19sm2650728wmb.42 - gsmtp
GMail will require you to use XOAUTH to authenticate. Please look at this PR: https://github.com/vert-x3/vertx-mail-client/pull/94
You need to create a google app for it and get a token, either from the command line or using the oauth2 client after you setup the app.
I'll keep this issue open as a reminder that this information needs to be added to the manual.
Am I understanding well that if I use token generated via app passwords screen
and using that as password in config doesn't work anymore?
@pmlopes what's interesting was that when using the solution described here I was able to send mail using password generated in the Google Application passwords screen
The solution is using plain om.sun.mail:javax.mail:1.6.2
dependency
Ok, so you can try a different thing. If the application password works, perhaps you should block XOAUTH
from the SASL list. In that case XOAUTH
won't be used and the username/password approach will be used instead.
Look for the auth algorithms options on the mail client options. By default if none is set the following list is used:
"XOAUTH2",
"DIGEST-MD5",
"CRAM-SHA256",
"CRAM-SHA1",
"CRAM-MD5",
"PLAIN",
"LOGIN"
So if you would remove the first one, by saying:
DIGEST-MD5,
CRAM-SHA256,
CRAM-SHA1,
CRAM-MD5,
PLAIN,
LOGIN
And you can even remove more if you know the SASL used by javax.mail
So, what was the solution for this issue?
This solved the issue for me:
mailConfig.setAuthMethods("DIGEST-MD5, CRAM-SHA256, CRAM-SHA1, CRAM-MD5, PLAIN, LOGIN");
Hi @KlausSchaefersAtWork, with https://github.com/vert-x3/vertx-mail-client/issues/124 fixed in 4.0.0
+, if XOAUTH2
failed, it turns to next auth method supported by this client, would you please try ?
Hi, I cannot easily move to 4.0, I am stuck with 3.9. But thanks for letting me know. I will try to upgrade to Vertx 4.x in the next weeks.