- 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:
Login to Google account from here: 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 via SSH as root.
Open or create the
/etc/postfix/sasl/sasl_passwdfile and add the SMTP Host, username, and password information:
CONFIG_TEXT: [smtp.gmail.com]:587 firstname.lastname@example.org:password
Use the password from step #3.
Create the hash db file for Postfix by running the
# postmap /etc/postfix/sasl/sasl_passwd
Set required ownership/permissions for the following 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
/etc/postfix/main.cfto match the following example:
CONFIG_TEXT: relayhost = [smtp.gmail.com]:587
Define the following directives at 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