Relayhost gmail postfix

A great topic!

Relaying emails through Gmail using Postfix is a common setup for sending emails from a Linux server. Here's a step-by-step guide to help you configure Postfix to relay emails through Gmail:

Prerequisites:

  1. You have a Postfix mail server installed on your Linux server.
  2. You have a Gmail account with 2-Step Verification enabled (recommended).
  3. You have a static IP address or a dynamic IP address with a reliable DNS setup.

Step 1: Configure Postfix to use Gmail as a relay

Edit the Postfix configuration file /etc/postfix/main.cf using your preferred editor (e.g., sudo nano /etc/postfix/main.cf):

# Add the following lines at the end of the file
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_tls_security_level = encrypt

Here's what each line does:

Step 2: Create a Postfix user and password

Create a new Postfix user and password to authenticate with Gmail:

sudo postmap -q "smtp.gmail.com" mysql:/etc/postfix/mysql.cf

This command will create a new Postfix user and password in the /etc/postfix/mysql.cf file.

Step 3: Configure Postfix to use the new user and password

Edit the Postfix configuration file /etc/postfix/mysql.cf using your preferred editor:

# Add the following lines at the end of the file
user = postfixuser
password = postfixpassword

Replace postfixuser and postfixpassword with the actual values created in Step 2.

Step 4: Restart Postfix

Restart the Postfix service to apply the changes:

sudo service postfix restart

Step 5: Test the relay

Use the telnet command to test the relay:

telnet smtp.gmail.com 587

If everything is set up correctly, you should see a greeting message from the Gmail SMTP server.

Troubleshooting tips:

By following these steps, you should be able to configure Postfix to relay emails through Gmail. If you encounter any issues or have further questions, feel free to ask!