Setting Up Postfix to use Gmail


Table of Contents

    A quick list of commands to use gmail as a relay for postfix.

    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.