I am using my Gmail account and smtp.gmail.com
inside my web application to test and send email. when two factor authentication is ON for my Gmail account, it fails to send the email, however when I turn it off, the web application sends email successfully. Appreciate any kind of advice.
Asked
Active
Viewed 7.5k times
124

user217648
- 3,338
- 9
- 37
- 61
2 Answers
295
Create a custom app in you Gmail security settings.
- Log-in into Gmail with your account
- Navigate to https://security.google.com/settings/security/apppasswords
- In 'select app' choose 'custom', give it an arbitrary name and press generate
- It will give you 16 chars token.
Use the token as password in combination with your full Gmail account and two factor authentication will not be required.
Note: The link in step 2 will work only if you have 2-factor-authentication enabled.

Stoyan Dimov
- 5,250
- 2
- 28
- 44
-
5Works perfectly, should be marked as a solution. Sadly gmail documentation is not that simple. – vearutop Sep 11 '15 at 16:15
-
Works. I'm using the SMTP plugin in Drupal 7 w/ these gmail credentials. – Kristopher Windsor Oct 17 '16 at 05:10
-
1Where i should use my token? With my username or password? Can you please be more clearer? – Freedo May 17 '17 at 07:04
-
3@Freedo username remains the same, the new token should be used as a password – Stoyan Dimov May 17 '17 at 14:44
-
Doesn't this defeat the purpose of 2FA? Anyone could access your Google account with just the app password ... no? – Dan Jan 23 '19 at 19:32
-
1@Ze'ev it works on the premise that the password will be secure in your app. (The hope is that phones nowadays allow it to store app data securely.) But if you know the password is compromised, you can at least revoke it without breaking access for other apps. – mwfearnley Mar 08 '19 at 10:40
-
Would this work for sending mail from other accounts in Gmail itself? I have set my Gmail to check POP3 accounts and bring in my branded domain email into one place. My server company, though, does not provide SMTP service for sending, so I try to use Gmail. I can only send email from me@customdomain.com via smtp.gmail.com if I turn off 2 factor. The SMTP settings only allow the Gmail username and password, there is no place for a custom 16 digit string, so I assume not. – J. Hogue Apr 22 '19 at 14:25
-
This does not work with Gnome Evolution Mail nor with Geary Mail. I created app passwords, and both apps can receive mail from Gmail (imap.gmail.com), but neither can send messages by SMTP. – Alexey Jul 22 '19 at 10:15
-
I've figured out that to make Evolution send mail, i had to check "Server requires authentication" checkbox and to activate OAuth2. – Alexey Jul 22 '19 at 10:46
-
Best answer. App password solved my problem. App password is only required to work in real server. App password will not work unless 2 step verification is on. So before generating app password one should enable 2step verification first – Ariful Islam Nov 11 '21 at 05:33
-
1Note that the link only works once you've enabled 2FA. – jtbr Dec 06 '21 at 11:18
-
@jtbr The link doesn't seem to work for me, but the account does have 2fa because when I login it asks me to either use a backup code or etc etc – LuisAFK Nov 13 '22 at 08:56
-
@LuisAFK if it asks you to backup codes, you don't have 2FA enabled yet. You are in the process of enabling it. – Stoyan Dimov Nov 14 '22 at 12:12
-
@StoyanDimov backup codes are an option, I can also choose "Tap yes on your phone or tablet", etc which is 2FA – LuisAFK Nov 15 '22 at 10:15
6
If you are here because of difficulties with the ARQ backup app on Mac OSX, I found the following settings worked for me:
SMTP hostname: smtp.gmail.com
SMTP Port: 587
Click: Enable SSL (STARTTLS)
Authentication Type: Password (SASL PLAIN)
User Name: <full Gmail email address>
Password: <Google-generated app password>
The Google-generated app password is generated as @stoyan-dimov suggests in his answer above, using the following URL:
https://security.google.com/settings/security/apppasswords
Choose to generate a 'Mail' password, and set the device as 'Custom' (I called mine "ARQ".)
Caveat: You must have two-factor authentication enabled on your Google account to get to the above URL.

RichTBreak
- 559
- 6
- 11