126

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.

0

2 Answers 2

308

Create a custom app in you Gmail security settings.

  1. Log-in into Gmail with your account
  2. Navigate to https://security.google.com/settings/security/apppasswords
  3. In 'select app' choose 'custom', give it an arbitrary name and press generate
  4. 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.

14
  • 7
    Works perfectly, should be marked as a solution. Sadly gmail documentation is not that simple.
    – vearutop
    Commented Sep 11, 2015 at 16:15
  • 1
    Where i should use my token? With my username or password? Can you please be more clearer?
    – Freedo
    Commented May 17, 2017 at 7:04
  • 4
    @Freedo username remains the same, the new token should be used as a password Commented May 17, 2017 at 14:44
  • 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
    Commented Mar 8, 2019 at 10:40
  • 1
    Note that the link only works once you've enabled 2FA.
    – jtbr
    Commented Dec 6, 2021 at 11:18
7

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.