Gmail smtp SASL authentication

23.8k views Asked by At

I'm using postfix to send email via gmail with an application's password (two step-validation activated).

Each time I test sending mail using sendmail command, I get this error:

Action: delayed
Status: 4.7.14
Diagnostic-Code: X-Postfix; delivery temporarily suspended: SASL authentication
failed; server smtp.gmail.com said: 534-5.7.14
<https://accounts.google.com/signin/continue?...> Please log in via your web browser and?534-5.7.14 then try again.?534-5.7.14

This is my postfix configuration:

main.cf

myorigin = /etc/mailname
mydestination = mydomain.com, localhost.fr, localhost
relayhost = [smtp.gmail.com]:587

smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
smtp_tls_security_level = encrypt
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

/etc/postfix/sasl/sasl_passwd:

[smtp.gmail.com]:587 [email protected]:application_password

And this is how I used sendmail:

sendmail -v ...
From: [email protected]
Subject: Test
This is a test mail
.

Any ideas ? Thanks !

3

There are 3 answers

3
Pipo On

Allow less secure apps: If you don't use 2-Step Verification, you might need to allow less secure apps to access your account.

enter image description here

0
jcaruso On

For anyone finding this who has run into the same scenario:

  1. Using an app specific password
  2. 2FA enabled on your account
  3. Seeing 'delivery temporarily suspended: SASL authentication failed; server smtp.gmail.com[173.194.68.109] said: 534-5.7.9 Please log in with your web browser and then try again' in your log

You may need to visit https://accounts.google.com/DisplayUnlockCaptcha to 'bypass' the captcha, which will enable the account access and get everything working.

1
Stefan On

In my case i was connecting from Synology NAS Mail Server with SMTP Relay. The solution is to:

  1. visit your Google account
  2. click Security
  3. search and click "App Passwords" (type "other app")
  4. create an app password and copy it to clipboard
  5. login form your app using your full email as username and the password from the clipboard as password

For Synology this should be:

  • enable relay: true
  • server: smtp.gmail.com
  • port: 587
  • always use TLS: true
  • authentication neccessary: true
  • account: [your-full-email-address]
  • password: [the-app-password-you-just-created]