Recently I was engaged on setting up mail client on the new redhat (rhel6) server for one of my clients. The server was on its default setup of sendmail. Since it is a bit outdated, I decided to use postfix relaying on gmail SMTP.
First thing first, make sure sendmail is not running by running this command
sudo service sendmail stop
Make sure if there are any lingering processes out there by issuing proper process listing commands on your server and kill those if you have to
Then check if you have postfix installed your machine
sudo service postfix start
If you got any complaint like service not found or something along that line, just install the postfix
sudo yum install postfix
Ok now lets go to the juicy part of integrating the postfix with gmail SMTP.
Lets assume your username is email@example.com and password is #nomoresendmail
Now lets proceed to the configuration part of the postfix.
go to postfix config folder
Here you will see a couple of files. Our interest would be on the main.cf file
First, before you start messing with the file, create a copy of it
sudo cp mail.cp main.cp.bak
Just go to the end of file and add the following snippet in there
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/pki/tls/certs/self.pem relayhost = [smtp.gmail.com]:587
That last line right there would tell the postfix it has to relay the SMTP to other server.
Now lets create the sasl_passwd file
sudo touch sasl_passwd echo "[smtp.gmail.com]:587 firstname.lastname@example.org:#nomoresendmail" > sasl_passwd
The above command would add the content to the sasl_passwd file.
Then to obscure the password information you placed on in the sasl_passwd file,
sudo postmap /etc/postfix/sasl_passwd
The other point would be creating a self certificate you would be using for your secure communication. If you have a certificate you are using already, then just point it to the right place and you should be fine
cd /etc/pki/tls/certs/ make self.pem
The above command would give you interactive wizard that you will follow and create the certificate.
After this, you need to tell the postfix to pick the changes you have been ramming. For that just restart postfix
sudo service postfix restart
Then open your logger to see if there are anything that are suspicious going or if mail is not working, you can tail it as
1. Google might be sending some kind of error saying you have to log into the web browser bla bla bla.. then do the following
Go to https://www.google.com/settings/security/lesssecureapps and login with your google account and turn it on