Redhat EL 7.2 using postfix to use smtp.gmail.com to relay not working

big toe asked:

I am running rhel 7.2, I have postfix installed and can’t get it to relay through gmail smtp servers. I have followed lots of tutorials and googled and tried answers to lots of others posts but I can’t seem to get anything to work.

This is the current error I have in the /var/log/maillog (i replaced the hostname and email addresses with x for privacy:

Jun 30 16:35:15 xxxxxxxx postfix/qmgr[31716]: 1DC08C13E1CA: from=<root@xxxxxxxxxx.localdomain >, size=277, nrcpt=1 (queue active)
Jun 30 16:35:15 xxxxxxxx postfix/smtp[31846]: 1DC08C13E1CA: to=<xxxxxxxx@xxxxxx.com>,  relay=smtp.gmail.com[173.194.193.109]:587, delay=3512, delays=3512/0.02/0.31/0.04, d sn=5.5.1, status=bounced (host smtp.gmail.com[173.194.193.109] said: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1  https://support.google.com/mail/answer/14 257 z205sm11773703itc.11 - gsmtp (in reply to MAIL FROM command))
Jun 30 16:35:15 inigo postfix/cleanup[31848]: 9544CC13E1CF: message-id=<2016063022351 5.9544CC13E1CF@inigo>
Jun 30 16:35:15 xxxxxxxx postfix/bounce[31847]: 1DC08C13E1CA: sender non-delivery notifi cation: 9544CC13E1CF
Jun 30 16:35:15 xxxxxxxx postfix/qmgr[31716]: 9544CC13E1CF: from=<>, size=2283, nrcpt=1  (queue active)
Jun 30 16:35:15 inigo postfix/qmgr[31716]: 1DC08C13E1CA: removed
Jun 30 16:35:15 inigo postfix/smtp[31846]: 9544CC13E1CF: to=<root@xxxxxxxxxx.localdomain>,  relay=smtp.gmail.com[173.194.193.108]:587, delay=0.32, delays=0.01/0/0.28/0.03, dsn= 5.5.1, status=bounced (host smtp.gmail.com[173.194.193.108] said: 530-5.5.1 Authentic ation Required. Learn more at 530 5.5.1  https://support.google.com/mail/answer/14257  p131sm3141384itg.17 - gsmtp (in reply to MAIL FROM command))
Jun 30 16:35:15 xxxxxxxxxx postfix/qmgr[31716]: 9544CC13E1CF: removed

I have tried multiple solutions from answers online and this is what my /etc/postfix/main.cf file ended up looking like:

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
myhostname = xxxxxxxx
myorigin = $myhostname
inet_interfaces = 10.10.10.10,127.0.0.1
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost
unknown_local_recipient_reject_code = 550
mynetworks = 127.0.0.0/8, 10.10.10.0/24
relayhost = [smtp.gmail.com]:587
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
home_mailbox = Maildir/
smtpd_banner = $myhostname ESMTP
debug_peer_level = 2
debugger_command =
     PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
     ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.10.1/samples
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
message_size_limit = 10485760
mailbox_size_limit = 1073741824
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtp_sasl_local_domain = $myhostdomain
smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated,reject
smtp_use_tls = yes
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
smtp_sasl_password_maps = hash:/etc/postfix/sasl/passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_policy_maps = hash:/etc/postfix/tls_policy
smtp_tls_security_level = secure
smtp_tls_mandatory_protocols = TLSv1
smtp_tls_mandatory_ciphers = high
smtp_tls_secure-cert_match = nexthop
smtp_tls_CApath = /etc/ssl/certs
smtpd_tls_CAfile = /etc/postfix/cacert.pem
debug_peer=smtp.gmail.com
debug_peer_level=3`

by the way postfix is the owner of the /etc/postfix/sasl/passwd file

If anyone has any suggestions I would greatly appreciate it!!!

My answer:


Check that you have formatted /etc/postfix/sasl/passwd correctly.

It should appear as:

smtp.gmail.com     user@gmail.com:password_or_app_password

After setting this file, you need to run postmap on it, to update the hash.

postmap /etc/postfix/sasl/passwd

Then reload postfix.

systemctl reload postfix

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.