- Plesk for Linux
How to set up Postfix to send emails using Gmail Relay with authentication?
Warning: the article provides an example of the general configuration and the final configuration on a particular server may differ. Thus, all actions below are performed at your own risk.
Warning: any customization made in Postfix configuration can be overwritten by Plesk update (for example, in case of bug fix, when configuration files are updated), Plesk upgrade or by
mchk utility, which resets default mail server configuration.
Set up the relay with authentication using smtp.gmail.com as a relay host in the following way:
Go to the following link: Manage your account access and security settings . Scroll down to “Password & sign-in method” and click 2-Step Verification. Then enable it.
Click the following link to Generate an App password for Postfix.
Click Select app and choose Other (custom name) from the drop-down menu. Enter “Postfix” and click Generate . Save the password.
Log in to Plesk server using SSH.
Open or create the
/etc/postfix/sasl/sasl_passwdfile and add the SMTP Host, username, and password information:
CONFIG_TEXT: [smtp.gmail.com]:587 email@example.com:password
Use the password from the 3d step.
Create the hash db file for Postfix by running the
# postmap /etc/postfix/sasl/sasl_passwd
Run the following commands to change the ownership to root and update the permissions for the two files:
# sudo chown root:root /etc/postfix/sasl/sasl_passwd /etc/postfix/sasl/sasl_passwd.db
# sudo chmod 0600 /etc/postfix/sasl/sasl_passwd /etc/postfix/sasl/sasl_passwd.db
Find and modify
/etc/postfix/main.cfto match the following example:
CONFIG_TEXT: relayhost = [smtp.gmail.com]:587
Set this in the end of
CONFIG_TEXT: # Enable SASL authentication
smtp_sasl_auth_enable = yes
# Disallow methods that allow anonymous authentication
smtp_sasl_security_options = noanonymous
# Location of sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
# Enable STARTTLS encryption
smtp_tls_security_level = encrypt
# Location of CA certificates
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
# service postfix restart