Setting up Postfix relay

There are many reasons why you would want to configure Postfix to send email using an external SMTP provider such as Google Apps (Gmail), Mandrill, SendGrid, Amazon SES, or any other SMTP server. One reason is to avoid getting your mail flagged as spam if your current server’s IP has been added to a spam list.

In this tutorial, you will learn how to install and configure a Postfix server to send email through Google Apps, Mandrill, or SendGrid.

Relaying Postfix SMTP

sudo aptitude install postfix libsasl2 ca-certificate libsasl2-modules libsasl2-modules

select satellite system

edit /etc/postfix/main.cf

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

Create the file /etc/postfix/sasl_passwd with

[smtp.gmail.com]:587    user.name@gmail.com:password

Change permissions

sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd

To authenticate the self signed cert 

cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem

sudo aptitude install postfix libsasl2 ca-certificates libsasl2-modules libsasl2-modules

restart postfix

sudo /etc/init.d/postfix restart

Testing Postfix

 echo "My message" | mail -s subject user@gmail.com