Thursday | 21 NOV 2024
[ previous ]
[ next ]

Setting Up Postfix to use Gmail

Title:
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:

[smtp.gmail.com]:587    username@gmail.com:password

Now edit /etc/postfix/main.cf and add the following:

relayhost = [smtp.gmail.com]: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" recipient@domain.com

Voila! Now postfix is using gmail to send mail.