homehowtokbslinksaboutcontactprojectsmusic

Index > Help Tutorials > Setup Postfix on Ubuntu to relay via Google
Apply the updates if any
sudo apt-get update; apt-get dist-upgrade
Install packages needed for this setup
sudo apt-get install postfix mailutils mutt libsasl2-2 ca-certificates libsasl2-modules
Update postfix configuration, simply copy and paste the following in terminal
cat << EOT >> /etc/postfix/main.cf

# Google relay configuration
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

# Maildir setup
home_mailbox = Maildir/
mailbox_command = 
EOT
Setup google mail credentials, again copy and paste into terminal and dont forget to change the values afterward
cat << EOT > /etc/postfix/sasl_passwd
smtp.gmail.com:587    USERNAME@gmail.com:PASSWORD
EOT
Change the credentials, replace USERNAME and PASSWORD values with your own credentials
nano /etc/postfix/sasl_passwd
Apply the permission to credential file and generate hashed password
sudo chmod 400 /etc/postfix/sasl_passwd; sudo postmap /etc/postfix/sasl_passwd
Append Thawte_Premium_Server_CA.pem certificate to cacert.pem
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
If Thawte cert not found then
cat << eot > /etc/postfix/cacert.pem
-----BEGIN CERTIFICATE-----
MIIDNjCCAp+gAwIBAgIQNhIilsXjOKUgodJfTNcJVDANBgkqhkiG9w0BAQUFADCB
zjELMAkGA1UEBhMCWkExFTATBgNVBAgTDFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJ
Q2FwZSBUb3duMR0wGwYDVQQKExRUaGF3dGUgQ29uc3VsdGluZyBjYzEoMCYGA1UE
CxMfQ2VydGlmaWNhdGlvbiBTZXJ2aWNlcyBEaXZpc2lvbjEhMB8GA1UEAxMYVGhh
d3RlIFByZW1pdW0gU2VydmVyIENBMSgwJgYJKoZIhvcNAQkBFhlwcmVtaXVtLXNl
cnZlckB0aGF3dGUuY29tMB4XDTk2MDgwMTAwMDAwMFoXDTIxMDEwMTIzNTk1OVow
gc4xCzAJBgNVBAYTAlpBMRUwEwYDVQQIEwxXZXN0ZXJuIENhcGUxEjAQBgNVBAcT
CUNhcGUgVG93bjEdMBsGA1UEChMUVGhhd3RlIENvbnN1bHRpbmcgY2MxKDAmBgNV
BAsTH0NlcnRpZmljYXRpb24gU2VydmljZXMgRGl2aXNpb24xITAfBgNVBAMTGFRo
YXd0ZSBQcmVtaXVtIFNlcnZlciBDQTEoMCYGCSqGSIb3DQEJARYZcHJlbWl1bS1z
ZXJ2ZXJAdGhhd3RlLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0jY2
aovXwlue2oFBYo847kkEVdbQ7xwblRZH7xhINTpS9CtqBo87L+pW46+GjZ4X9560
ZXUCTe/LCaIhUdib0GfQug2SBhRz1JPLlyoAnFxODLz6FVL88kRu2hFKbgifLy3j
+ao6hnO2RlNYyIkFvYMRuHM/qgeN9EJN50CdHDcCAwEAAaMTMBEwDwYDVR0TAQH/
BAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQBlkKyID1bZ5jA01CbH0FDxkt5r1DmI
CSLGpmODA/eZd9iy5Ri4XWPz1HP7bJyZePFLeH0ZJMMrAoT4vCLZiiLXoPxx7JGH
IPG47LHlVYCsPVLIOQ7C8MAFT9aCdYy9X9LcdpoFEsmvcsPcJX6kTY4XpeCHf+Ga
WuFg3GQjPEIuTQ==
-----END CERTIFICATE-----
eot
if everything looks good then restart the service
service postfix restart

Testing

If you have configured everything correctly, following command should generate a test mail from your server to your mailbox.
echo "Test mail from postfix" | mail -s "Test Postfix" you@domain.com
replace you@domain.com with your email address from any provider like gmail, hotmail, live, yahoo etc..
Now check this test email in the account you just sent email to. I tested on live.com and mail was there

Reference 1
Reference 2