I am trying to setup our web server so that it can send emails from various web apps to reset password etc. Our mail is hosted by Gmail with a custom domain eg. mydomain.com.

Right now emails going to various domains just sit in the mail queue. Anything that is sent to someuser@mydomain.com doesn't even make it to the queue.

How do I route the SMTP server through Gmail?

This is what I've added to `/etc/postfix/main.cf`

relayhost = smtp.mydomain.com:587
smtp_tls_security_level = verified
smtp_tls_mandatory_protocols = TLSv1
smtp_tls_mandatory_ciphers = high
smtp_tls_secure_cert_match = nexthop
smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

Should the relayhost be set to smpt.gmail.com? Do I need to change the DNS?


if you want all the emails being sent via gmail, you have to set relayhost to smtp.gmail.com:587 as you wrote.

This is not enough, though.

You need to create and edit the file /etc/postfix/sasl_passwd Write a line in it like below:

smtp.gmail.com:587 user@example.com:password



is a valid username in your gmail hosted domain and the sender of all email routed via your mail server.

When done, create its hashed version. Run:

postmap /etc/postfix/sasl_passwd

and restart postfix.

  • ok, so I see the messages in the Queue now, but they aren't getting sent out, just sitting there. The From email however is not the same as the one in the sasl_passwd file, so maybe that's the issue now – keeg Jun 21 '16 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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