Search:  
Gentoo Wiki

HOWTO_Gmail_and_sSMTP

Contents

Installation

To get this running, I followed the documents @ the bottom of this post. Here's the condensed version:

## note that the following just enables mailwrapper in ssmtp 
## this is "to allow multiple MTAs to be installed".  So if one is already using ssmtp one shant need that use flag.
# echo "mail-mta/ssmtp mailwrapper" >> /etc/portage/package.use
# emerge ssmtp

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

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

In /etc/ssmtp/revaliases:

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

Usage

Install mailx (the package that contains /bin/mail):

# emerge mailx

Test with:

$ mail user@domain.tld
To: user@domain.tld
From: ssmtp@localhost
Subject: sSMTP test

Message body.
<Ctrl+D>

Check the remote account (user@domain.tld) to make sure the mail arrived.

Troubleshooting

Failed Mail Delivery

If mail delivery fails ssmtp stores message in ~/dead.letter. You can resend it later using command

$ cat ~/dead.letter | sendmail user@domain.tld

If mail sending works as root, but not as regular user, make sure user is in group ssmtp

gpasswd -a <user> ssmtp

If sendmail is not found, you may need to reemerge ssmtp WITHOUT mailwrapper flag or set a link from sendmail to ssmtp

ln -s /usr/sbin/ssmtp /usr/sbin/sendmail

Take a look to /var/log/messages to get more info (syslog must be installed).

If mail return a "command not found" error, you meed to install mail client like nail (emerge nail). If mail runs but then errors with "/usr/sbin/sendmail command not found" remerge mailwrapper (emerge mailwrapper). Other solution for non existing sendmail command is to recompile ssmtp without mailwrapper flag.

Source address and recipient are the same GMail account

If your source E-Mail address and recipient are the same GMail account, messages do not appear in your Inbox as normal. If you search for them they can be found, but they are effectively marked as "Read" and will not display in the Inbox list.

The quickest solution to this problem is to open another GMail account for use as your mail source, such as "JohnDoeMailDaemon@gmail.com", with your destination address for "root" defined as your primary GMail account.

An example ssmtp.conf would look like so:

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

You can then configure a Gmail Filter in your recipient GMail account to mark messages from your Linux system with a Label, and also color that label so these messages appear in your Inbox and stand out.

Resources

Authors

Retrieved from "http://www.gentoo-wiki.info/SSMTP_with_GMail"

Last modified: Thu, 02 Oct 2008 04:56:00 +0000 Hits: 20,353