Use Gmail SMTP for relay server on Postfix

  1. Install Postfix on your server:
    • On Debian/Ubuntu systems, you can use the following command: sudo apt-get install postfix
    • On CentOS/Red Hat systems, you can use the following command: sudo yum install postfix
  2. Once Postfix is installed, open the main configuration file using your favorite text editor: sudo nano /etc/postfix/main.cf
  3. Find the following lines in the configuration file and modify them as follows:
    • relayhost = [smtp.gmail.com]:587
    • smtp_sasl_auth_enable = yes
    • smtp_sasl_security_options = noanonymous
    • smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
  4. Next, create a new file called sasl_passwd in the /etc/postfix directory: sudo nano /etc/postfix/sasl_passwd
  5. Add the following line to the sasl_passwd file, replacing [email protected] and password with your Gmail address and password: [smtp.gmail.com]:587 [email protected]:password
  6. Save and close the sasl_passwd file, then run the following command to create a hashed version of the file: sudo postmap /etc/postfix/sasl_passwd
  7. Finally, restart the Postfix service to apply the changes: sudo service postfix restart

You should now be able to use Gmail’s SMTP server to send emails through Postfix.

Leave a Reply

Your email address will not be published. Required fields are marked *