How to Install Postfix: Using Gmail as a Relay Host

How to Install Postfix: Using Gmail as a Relay Host.

Postfix is a free and open-source mail transfer agent (MTA) that routes and delivers electronic mail.It is released under the IBM Public License 1.0 which is a free software license.Originally written in 1997 by Wietse Venema at the IBM Thomas J. Watson Research Center and first released in December 1998, Postfix continues as of 2017 to be actively developed by its creator and other contributors. The software is also known by its former names VMailer and IBM Secure Mailer.

Before you start installation you need to have Gmail Account.

Install Postfix by run this command:

sudo apt-get install postfix

After go and edit /etc/postfix/main.cnf :
vi /etc/postfix/main.cnf
Paste the lines.
# Forward mail through Gmail
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/ssl/certs/Equifax_Secure_CA.pem

Next, create /etc/postfix/sasl_passwd file:
vi /etc/postfix/sasl_passwd
And add this line:
[smtp.gmail.com]:587 [yourusername]@gmail.com:[yourpassword]
Note: Change [yourusername] and [yourpassword] with your Gmail access details.

Now modify file permissions and generate sasl_passwd.db by running these commands one by one:
cd /etc/postfix
postmap sasl_passwd
chmod 600 sasl_passwd sasl_passwd.db

Now restart the postfix to have affected.
sudo service postfix restart

After, send a test email:
sudo apt-get install mailutils

And:
echo 'Success!' | mailx -s 'Test Message' [youremail_address]

Note: Change [youremail_address] with your email.

Now you have successfully installed Postfix.

Enjoy

POSTFIX Logo

Register for free account now.