Using SSMTP with GMAIL

I’ve posted this before on the Archlinux.org forums, but thought I’d repost it here as well for future reference for myself, and anyone else that’s interested.
I’ve made a few changes to the original article and hopefully made it even more clear how to do this with Arch Linux.

SSMTP with GMail
In arch this is very simple to setup.
If your like me, you don’t always need a full blown mail server, since I use gmail (my @archlinux.us email )for most everything. But it’s nice to have a quick easy way to get automated mail off your machine and to a mail hub. Enter ssmtp, the quick and painless way to do this.

[crouse@VistaCrusher ~]$ pacman -Ss ssmtp
extra/ssmtp 2.62-2
Extremely simple MTA to get mail off the system to a mailhub

Installing in arch…. piece of cake…..

[root@VistaCrusher ~]# pacman -S ssmtp
resolving dependencies...
looking for inter-conflicts...

Targets (1): ssmtp-2.62-2
Total Download Size: 0.02 MB
Total Installed Size: 0.07 MB
Proceed with installation? [Y/n] y
:: Retrieving packages from extra...
ssmtp-2.62-2-x86_64 21.4K 63.6K/s 00:00:00 [######################] 100%
checking package integrity...
(1/1) checking for file conflicts [######################] 100%
(1/1) installing ssmtp [######################] 100%
[root@VistaCrusher ~]#

Now you have 2 files to edit.
In /etc/ssmtp/revaliases:

root:youraccount@gmail.com:smtp.gmail.com:587
mainuser:youraccount@gmail.com:smtp.gmail.com:587

In /etc/ssmtp/ssmtp.conf, set the following:

root=youraccount@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=youraccount@gmail.com
UseSTARTTLS=YES
AuthUser=youraccount
AuthPass=yourpasword
FromLineOverride=YES

I setup mine for my @archlinux.us account…… works great.
> cat ssmtp.conf | grep -v “#”
root=XXXXXXXX@archlinux.us
mailhub=smtp.gmail.com:587
rewriteDomain=archlinux.us
hostname=archlinux.us
UseSTARTTLS=YES
AuthUser=XXXXX@archlinux.us
AuthPass=XXXXXXXX
FromLineOverride=YES

You can test if it’s working by sending your email (to a different account than what you setup for ) by opening a terminal……

echo test | mail -s “testing ssmtp setup” USERNAME@SOMEDOMAIN.COM

USERNAME@SOMEDOMAIN.COM would of course be an email YOU can check.

That’s all folks, it’s THAT simple :)

5 Comments

  1. securitybreach says:

    Thanks for the help and the blog post but I am still getting an weird error:

    bash-4.0$ echo test | mail -s “testing ssmtp setup” securitybreach@archlinux.us
    bash-4.0$ send-mail: Cannot open mailhub:25

    Now you would assume that the hub entry was wrong in the /etc/ssmtp/ssmtp.conf:

    mailhub=smtp.gmail.com:587

    So I wonder why I get an error about port 25 when the hub uses 587. I pinged the address just fine so it is reachable and I also opened port 587 and 25 on my router.

    Any ideals? I will post on the forum thread if you wish.

    THanks

  2. crouse says:

    Your original file had: UseTLS=YES

    Make sure it’s set to: UseSTARTTLS=YES

    After that, if it still doesn’t work, post both files in the forums and we can try again ;)

  3. securitybreach says:

    Thanks alot

  4. crouse says:

    perhaps add your user to group: smmsp

  5. John Sabboth says:

    FIXED. I was the permissions on /usr/sbin/ssmtp. I did chmod 4555 /usr/sbin/ssmtp and now I can send mail as regular user.

    Thanks for the help