Share

Sunday, April 3, 2016

Google SMTP server as your mail server on Linux Mint / ubuntu

Step 1:  Install mail utilities using get-apt

sudo apt-get install mailutils


Step 2: Update main.cf of "postfix" utility with following configuration elements.

"Postfix is a free and open-source mail transfer agent (MTA) that routes and delivers electronic mail, intended as an alternative to the widely used Sendmail MTA."


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


Step 3: Update your user credentials of  your desired google account in /etc/postfix/sasl_passwd file

[smtp.gmail.com]:01    middlewareinventory@gmail.com:<password>

Step 4: map the password file sasl_passwd to postfix using 'postmap' command

postmap /etc/postfix/sasl_passwd1

Step 5: Reload and Restart postfix MTA.

sudo /etc/init.d/postfix reload
sudo /etc/init.d/postfix stop
sudo /etc/init.d/postfix start

Step 6: Visit http://www.google.com/accounts/DisplayUnlockCaptcha and sign in with your Gmail username and password. If asked, enter the letters in the distorted picture.


Step 7: Allow less secure apps access to your account in google account settings in this link https://www.google.com/settings/security/lesssecureapps



It's time to test

echo "Test mail from Server" | mail -s "TestEmail" sara@mwinventory.in

If everything went well ( If I am not wrong in any previous steps :P)  You should be able to see the message getting delivered to the destination email id. you could also verify it in the system log files like /var/log/mail.log (or) /var/log/syslog

Apr  3 22:54:23 mwi-virtual-machine postfix/pickup[11537]: 0F4A21053D1: uid=1000 from=<mwi@mwi-virtual-machine>
Apr  3 22:54:23 mwi-virtual-machine postfix/cleanup[11646]: 0F4A21053D1: message-id=<20160403172423.0F4A21053D1@mwi-virtual-machine>
Apr  3 22:51:52 mwi-virtual-machine postfix/qmgr[11538]: BE5A71053CD: from=<mwi@mwi-virtual-machine>, size=377, nrcpt=1 (queue active)
Apr  3 22:54:23 mwi-virtual-machine postfix/qmgr[11538]: 0F4A21053D1: from=<mwi@mwi-virtual-machine>, size=377, nrcpt=1 (queue active) 


Additionally, You should also be able to see the "Sent" email in the "Sentitems" of your gmail web login.

Hope it helps.

Thanks,
Sarav
sara@mwinventory.in

No comments :

Post a Comment