I'm trying to configure a machine so that it will send me an email if one of the cronjobs output something in case of an error.

  • I'm using Debian Wheezy.
  • Cron is working normally (without the email functionality).
  • msmtp is installed and configured. Have already symlinked /usr/{bin|sbin}/sendmail to /usr/bin/msmtp.

I can send email by using:

echo "test" | mail -s "subject" user@target.tld

or by executing:

echo "test" | /usr/sbin/sendmail

Without the symlink (/usr/sbin/sendmail) cron will tell me that:

(CRON) info (No MTA installed, discarding output)

With the symlinks I get:

(root) MAIL (mailed 1 byte of output; but got status 0x004e, #012)

Can you suggest how to config the cron/msmtp pair?



Note: I've written "msmtpd" by mistake. Its not a daemon but rather an SMTP client named just "msmtp" (without the "d" ending). It is executed on demand and it is not running in the background all the time.

When I try to send an email by using msmtp like that it works:

echo "test" | msmtp USER@TARGETHOST.TLD

On the far side, in the logs of the SMTP server I read:

Nov  2 09:26:10 S01 postfix/smtpd[12728]: connect from unknown[CLIENT_IP]
Nov  2 09:26:12 S01 postfix/smtpd[12728]: 532301C318: client=unknown[CLIENT_IP], sasl_method=CRAM-MD5, sasl_username=USER@TARGETHOST.TLD
Nov  2 09:26:12 S01 postfix/cleanup[12733]: 532301C318: message-id=<>
Nov  2 09:26:12 S01 postfix/qmgr[2404]: 532301C318: from=<USER@TARGETHOST.TLD>, size=191, nrcpt=1 (queue active)
Nov  2 09:26:12 S01 postfix/local[12734]: 532301C318: to=<FORWARD_TO@TARGETHOST.TLD>, orig_to=<USER@TARGETHOST.TLD>, relay=local, delay=0.62, delays=0.59/0.01/0/0.03, dsn=2.0.0, status=sent (delivered to command: IFS=' ' && exec /usr/bin/procmail -f- || exit 75 #1001)
Nov  2 09:26:12 S01 postfix/qmgr[2404]: 532301C318: removed
Nov  2 09:26:13 S01 postfix/smtpd[12728]: disconnect from unknown[CLIENT_IP]

And the Email is delivered to the target user. So it looks like that the msmtp client is working properly.

It has to be something in the cron/msmtp integration, but I have no clue what that thing might be. Can you help me?

  • @josten, please take a look at the EDIT I've made. 10x a lot. – Glister Nov 2 '13 at 10:07
  • You don't need the symlinks if you install msmtp-mta instead. – colan Dec 6 '13 at 15:32

The solution was to add to the cron configuration for my user (by invoking crontab -e) this:

  • This worked for me on CentOS 7, but not on Debian unstable. I think it only works for some versions of the cron daemon, namely cronie. – jobo3208 Jan 14 '16 at 15:47
  • This didn't work on Ubuntu Xenial LTS running ISC Cron (aka Vixie Cron). – ILIV Sep 3 '16 at 5:36
  • 1
    The reason this didn't help in my case is because ISC Cron (default on Ubuntu Xenial LTS) doesn't support the -m arugment. However, what helped me was installing msmtp-mta package which created sendmail symlinks that point to msmtp binary and installed the newaliases utility. – ILIV Sep 3 '16 at 7:32

I had exactly the same scenario as described in the question, however the current answer didn't fix the problem for me. In my case, the explanation of the problem was that every time when cron executed sendmail command it was setting $HOME to /, rather than /home/<user>. Thus even if msmtp replaced sendmail via a symlink it was not able to find its user-specific config file located in $HOME/.msmtprc.

My SOLUTION was to use /etc/msmtprc instead of $HOME/.msmtprc.

This may not be the best solution for your system, as it may force some sensitive data from your /etc/msmtprc to be readable by other users.

Read more here: http://comments.gmane.org/gmane.linux.debian.devel.bugs.general/671011

  • This doesn't help on Ubuntu Xenial LTS. I have /etc/msmtp.rc in place but ISC Cron (aka Vixie Cron) still complains "No MTA". – ILIV Sep 3 '16 at 5:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.