Booker

Thursday, April 7, 2016

Need mail server, tired of configuring mail servers ?

How to configure mail forwarder, using GMAIL as a gateway

Opening a security hole

visit:
https://www.google.com/settings/security/lesssecureapps
set it it to "Turn on"
A mail with notification will arrive at your mail and a spam notification on your Android device :@.


Otherwise google will send rejecting during authorization.

Mail gateway

sudo apt-get install ssmtp

sudo vim /etc/ssmtp/ssmtp.conf
root=damjandimitrioski@gmail.com
mailhub=smtp.gmail.com:587
hostname=freedom
FromLineOverride=YES
AuthUser=damjandimitrioski # not sure if username or it doesn't care for the domain
AuthPass={PUT YOUR PASSWORD}
FromLineOverride=yes
UseSTARTTLS=YES # Otherwise Google will complains about SSL stuff
sudo vim /etc/ssmtp/revaliases
# Replace root@ with whatever name
root:root@freedom:smtp.gmail.com:25

The resulting mail will be like this:
root <damjandimitrioski.gmail.com>

Testing 

echo "My mail content" | sudo ssmtp -vvv damjandimitrioski@gmail.com

PHP setup

 sudo vim /etc/php5/fpm/php.ini
locate the [mail function] section and uncomment it
sendmail_path = /usr/sbin/ssmtp -t 
After change, restart php service.
sudo service php5-fpm restart

Testing

$ php -a
php >  mail("petko@gmail.com", "My subject", "My ugly short content");