Sending email fails when two factor authentication is on for Gmail
Solution 1:
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.
Solution 2:
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.