4

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" [email protected]

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?

Thanks!

EDIT:

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 [email protected]

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, [email protected]
Nov  2 09:26:12 S01 postfix/cleanup[12733]: 532301C318: message-id=<>
Nov  2 09:26:12 S01 postfix/qmgr[2404]: 532301C318: from=<[email protected]>, size=191, nrcpt=1 (queue active)
Nov  2 09:26:12 S01 postfix/local[12734]: 532301C318: to=<[email protected]>, orig_to=<[email protected]>, 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?

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

4 Answers 4

1

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

CRONARGS=-m/usr/bin/msmtp
3
  • 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, 2016 at 15:47
  • This didn't work on Ubuntu Xenial LTS running ISC Cron (aka Vixie Cron).
    – ILIV
    Sep 3, 2016 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, 2016 at 7:32
1

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

1
  • 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, 2016 at 5:31
0

cron has an upstream. https://github.com/vixie/cron

please consider sending in the -m patch referenced here.

separately, i don't know how to get the distros who imported cron ~20 years ago to merge against the upstream. but we can do no less than try.

0

I know this is a stale question, but I had this issue and I fixed it by installing msmtp-mta alongside msmtp. I had configured my server with /etc/msmtprc and /etc/aliases though so my setup may be a bit different than the OP's.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .