Using msmtp for a desktop system

I read all my email via IMAP, and send all email via external SMTP servers, but at times it’s really useful to be able to run something like /usr/sbin/sendmail to send an email. Many tools depend on it, for me I want reports on cron jobs and I like using darcs send straight to an email address. For this a full-fledged SMTP server like exim/postfix/sendmail clearly is overkill. First I had a quick look at ssmtp but it only allows for a system-wide configuration file. Ideally I’d like “system-mails” (like cron) to be sent via my ISP while more personal emails should be sent via my Google account. After a suggestion on the Arch mailing list I checked out msmtp and it was exactly what I was looking for.

I created /etc/msmtprc with the following contents:

defaults
logfile ~/.msmtp.log
    
# MyISP
account myisp
host smtp.myisp.com
from my.email@myisp.com

account default : myisp

I then found out that [dcron][3] is severely limited; it doesn’t honour MAILTO in crontabs and it’s not possibly to use anything but /usr/sbin/sendmail to send emails. The lack of support for MAILTO is the deal breaker in this case.

Rather than create a symbolic link I modified fcron’s configuration file, /etc/fcron/fcron.conf, to use /usr/bin/msmtp:

sendmail = /usr/bin/msmtp

I also made sure to stick MAILTO=my.email@myisp.com in the system crontab, using fcrontab -u systab -e.

Then I created the file ~/.msmtprc:

defaults
logfile ~/.msmtp.log

# MyISP
account mysisp
host smtp.myisp.com
from my.email@myisp.com

# google
account google
host smtp.gmail.com
from user@googlemail.com
tls on
tls_certcheck off
auth on
user user@googlemail.com
password MySecretPassword

account default : google

Finally I put MAILTO=user@googlemail.com in my user’s crontab.

⟸ Reply to Randal on dynamic type systems Using msmtp with Mercurial ⟹

maltem

Is there anything to say about msmtp vs. esmtp? I’m an esmtp user, but msmtp looks, at first glance at least, to be more feature-ful.

Magnus

@maltem, Nope, I’ve never tried esmtp. Sorry.

Leave a comment