For this we need Ubuntu 12.04 LTS installed in your physical or virtual system.
Lets get started with this,
We need to install required packages for the same,
sudo apt-get install mailutils postfix libsasl2-2 ca-certificates libsasl2-modules
When you install postfix for the first time, system will ask you for the smtp domain name and smtp type. Select "Internet Site" and "smtp.yourdomain.com" where ever applicable. (Where 'yourdomain.com' is your working domain name)
Now lets start configuring SMTP in postfix.
sudo vim /etc/postfix/main.cf
(Edit configuration file, so that it looks like this..)
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
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
(Save & Exit)
Now your google user name and password goes in this file:
vim /etc/postfix/sasl_passwd
(Edit as below)
[smtp.gmail.com]:587 <GMAILUSERNAME>:<GMAILPASSWD>
(Save & Exit)
Lets make sure postfix can read this file and not everyone else:
sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
Lets use the certificate for the authentication:
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
and finally lets restart the postfix service:
/etc/init.d/postfix reload
Now let's test our configuration if its working or not:
echo "Test email from Postfix" | mail -s "Test Postfix" USERNAME@gmail.com
Verify is the mail is sent:
tail -f /var/log/mail.log
If required we can also add your gmail account in aliases:
vim /etc/aliases
root: GMAILADDRESS@gmail.com
(save & exit)
newaliases
Thanks for the visit
:)
No comments:
Post a Comment