Friends

Thursday, January 27, 2011

Send Email With sSMTP And Gmail

When I setup the server that runs this website I wanted to receive emails from my contact page and also from my backup jobs that run overnight.  There are many open source mail servers (MTAs) that can accomplish this, but most are overkill for just sending a few emails. sSMTP is a simple, lightweight MTA that will forward messages on a server to a configured mail server.  In my configuration sSMTP forwards mail from my Ubuntu server to Gmail.  With this configuration I don’t have to run a full mail server and can just send the few messages I have to Gmail to do the heavy lifting.

Nixtutor has a great article explaining how to configure this.  Here are the steps I used to get this working.
1.  Install sSMTP
From the command line:
sudo apt-get install ssmtp
2.  Configure sSMTP to send mail through your Gmail account
Open /etc/ssmtp/ssmtp.conf and set the following according to your own Gmail credentials.  The first four lines were already in my config file and just needed to be set.  I needed to manually add the last three lines.
root=username@gmail.com
mailhub=smtp.gmail.com:587
hostname=username@gmail.com
FromLineOverride=YES
UseSTARTTLS=YES
AuthUser=username
AuthPass=password
Open etc/ssmtp/revaliases and add each user account you want to send mail from.  Most likely you will want to add the root account and your primary user account.
root:username@gmail.com:smtp.gmail.com:587
linuxusername:username@gmail.com:smtp.gmail.com:587
3.  Test out the configuration by sending an email to yourself
From the command line:
sudo ssmtp username@gmail.com
Then type in your email message, hit enter and then ctrl + d to send the email.  If everything is working correctly, your email will show up in your inbox.

0 comments:

Post a Comment

#
### ###