Postfix : Gmail as Relay - Linux Mint/Ubuntu/Debian
Many ISPs block sending email over port 25. This means that you won’t be able to send mail directly from your Linux server.
A good way to get around this limitation is to set up a relay through a Gmail account.
1. Install the Required Packages
Execute the following command to install required packages :
2. Configure Postfix to use Gmail as Relay
Edit the Postfix configuration file :
Add the following lines :
# Relaying Postfix SMTP via GMAIL relayhost = [smtp.gmail.com]:587 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_tls_CAfile = /etc/postfix/cacert.pem smtp_use_tls = yes
3. Setup Gmail Credentials
Open (create) the file
Add the following line (set your Gmail username and password) :
Set the permissions and tell Postfix to use the
$ sudo postmap /etc/postfix/sasl_passwd
4. Validate the Certificate
Add the certificate to Postfix, as follows :
5. Test Postfix with Gmail SMTP Realy
Restart Postfix to apply all changes.
Try to send an email.
Check the mail log :
If all goes well, you should not see any errors.
Once configured, all emails from your server will be sent via Gmail.