How to use gmail as relay host for postfix in Ubuntu 12.04


first of all, please note that when the recipient receives your email, the sender will be changed to the gmail account you are going to use

Add the following code in /etc/postfix/

# Define relay host to gmail
relayhost =

# Gmail requires tls connections
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt #Your trusted CA list

# Gmail requires authentication
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

# define authentication mechanism
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = plain
smtp_sasl_tls_security_options = noanonymous

Then, edit your authentication file /etc/postfix/sasl_passwd as the following format:    USERNAME:PASSWORD

please note that username should be your full mail address, include “” or your own domain name.
then update the file to postfix format for using:

#postmap /etc/postfix/sasl_passwd

remember restart postfix at the last

#service postfix restart