Postfix relay gmail

A classic setup!

To set up postfix to relay emails to Gmail, you'll need to configure postfix to use Gmail's SMTP server as a relay. Here's a step-by-step guide:

Step 1: Install postfix

If you haven't already, install postfix on your system. The installation process varies depending on your Linux distribution. For example, on Ubuntu/Debian, you can run:

sudo apt-get install postfix

Step 2: Configure postfix

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

# Set the relayhost to Gmail's SMTP server
relayhost = [smtp.gmail.com:587]

# Set the mail_from address to your Gmail address
mydestination = [email protected]

# Set the mail_from address to your Gmail address
myorigin = [email protected]

# Set the SMTP authentication settings
smtp_use_tls = yes
smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

# Create a file for storing the Gmail password
sudo touch /etc/postfix/sasl_passwd
sudo chmod 600 /etc/postfix/sasl_passwd

# Add the Gmail password to the file
sudo echo "smtp.gmail.com:587 your-gmail-password" >> /etc/postfix/sasl_passwd

# Create a hash of the password file
sudo postmap /etc/postfix/sasl_passwd

Replace your-gmail-username and your-gmail-password with your actual Gmail username and password.

Step 3: Restart postfix

Restart the postfix service to apply the changes:

sudo service postfix restart

Step 4: Test the setup

Use the telnet command to test the setup:

telnet smtp.gmail.com 587

If everything is set up correctly, you should see a response from Gmail's SMTP server.

Step 5: Configure your mail client

Finally, configure your mail client (e.g., Thunderbird, Evolution) to use the Gmail SMTP server as the relay. You can do this by setting the SMTP server to smtp.gmail.com and the port to 587.

That's it! With these steps, you should be able to set up postfix to relay emails to Gmail.