cheatsheets devlog search


Setting Up Postfix to use Gmail

Title: Setting Up Postfix to use Gmail 
Date: 2021-04-04
Tags: []

A quick list of commands to use gmail as a relay for postfix. This also works for office365. I used these instructions to easily get things set up :)

First step is to install postfix and mailx.

# yum install postfix mailx cyrus-sasl cyrus-sasl-plain 

Next create /etc/postfix/sasl_passwd and add the following:


Now edit /etc/postfix/ and add the following:

relayhost = []:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt

Use postmap to hash the password so that postfix can use it.

# postmap /etc/postfix/sasl_passwd

Now enable postfix to start on boot and restart it.

# systemctl enable postfix
# systemctl restart postfix

We should now be able to send mail through gmail and we can test this through the following command.

# echo "Hello, World!" | mail -s "My First E-mail"

Voila! Now postfix is using gmail to send mail.