← all posts

Cron MAILTO not working? Where cron's email actually goes

We sent cron mail on Debian, Ubuntu, Fedora and Alpine and traced where it went: /var/mail, syslog, a refused port 25 or nowhere. Then made msmtp deliver it.

10 min read

You put [email protected] at the top of the crontab, broke a job on purpose, and waited. No email. Not in spam either.

Cron did try. It hands the job’s output to whatever /usr/sbin/sendmail is on the box and moves on, and what that program does with it depends on the distro. We ran the same crontab on Debian 13, Ubuntu 26.04, Fedora 43 and Alpine 3.22 and followed the mail.

0messages mail shows root on Debian 13. Root's cron mail is in /var/mail/mail
exit 1with no output: cron sends nothing at all
0x004ewhat Debian's cron logs when msmtp has no config, and the mail is gone
553the relay's answer to root, the sender cronie hands to sendmail

Short answer

Cron mails a job’s output, not its failures, and only through /usr/sbin/sendmail. What happens next is set by the distro:

  • Ubuntu, and most Docker images: no mail server, so the output is discarded and syslog gets (CRON) info (No MTA installed, discarding output).
  • Debian 13: apt install cron pulls in exim, configured for local delivery only. Root’s mail goes to /var/mail/mail, and mail to [email protected] bounces back into the same file.
  • Fedora, RHEL (cronie): with no sendmail installed, output goes to syslog as CMDOUT lines.
  • Alpine (BusyBox): sendmail is a BusyBox applet that connects to 127.0.0.1:25. Nothing listens there, so the mail is lost.

To get it into a real inbox, install msmtp-mta, point it at an SMTP relay, and add a root alias and a from address (config below). If what you actually want is mail when a job fails rather than when it prints, wrap jobs in chronic, or run them under a scheduler that alerts on the exit code. RunWisp, an open-source cron replacement that ships as a single binary, can send that mail through the same msmtp setup.

Distro, cron /usr/sbin/sendmail out of the box Root’s job output goes to [email protected]
Ubuntu 26.04, cron 3.0pl1-200 missing (MTA is only Suggested) discarded, one syslog line discarded
Debian 13, cron 3.0pl1-197 exim4, local delivery only /var/mail/mail bounces into /var/mail/mail
Fedora 43 minimal, cronie 1.7.2 missing syslog, one CMDOUT line per line syslog
Alpine 3.22, BusyBox 1.37 crond BusyBox applet, SMTP to 127.0.0.1 crond’s stdout (/dev/null on OpenRC) can't connect to remote host

Find the mail in two minutes

Run these in order. Most people stop at step 1 or 3.

# 1. Did the job print anything? No output = no mail, whatever the exit code.
#    Run it the way cron does, with cron's PATH and no terminal:
env -i PATH=/usr/bin:/bin HOME="$HOME" sh -c '/usr/local/bin/backup.sh' </dev/null

# 2. What did cron say about the mail?
journalctl -t CRON --since today | grep -E 'MTA|MAIL'      # Debian, Ubuntu
grep CROND /var/log/cron                                  # cronie

# 3. What is sendmail on this box?
readlink -f /usr/sbin/sendmail

# 4. Did it land locally?
ls -la /var/mail/

# 5. Did the mail server take it and fail later?
tail /var/log/exim4/mainlog; mailq

The two cron log lines worth knowing:

CRON[4211]: (CRON) info (No MTA installed, discarding output)
CRON[3708]: (root) MAIL (mailed 17 bytes of output but got status 0x004e from MTA )

The first means there’s no sendmail at all. The second means there is one and it failed; the status is its exit code in hex. 0x004e is 78, which msmtp returns when it has no config. Either way the output is gone. Cron doesn’t queue it or retry.

Cron mails output, not failures

This catches more people than any mail server. We ran these four jobs on each cron:

* * * * * echo "a: prints, exits 0"
* * * * * false
[email protected],[email protected]
* * * * * echo "b: two addresses"; exit 3
MAILTO=""
* * * * * echo "c: empty MAILTO"

false fails every minute and never sends a thing, because it prints nothing. The echo that succeeds sends a mail every minute. That’s how cron was designed: the mail is a copy of the output, and the exit code isn’t part of the decision.

Debian’s and Ubuntu’s cron can add one hint, if you turn it on. Start cron with a log level that includes failed jobs (EXTRA_OPTS="-L 5" in /etc/default/cron, then restart it), and a job that printed something and exited non-zero gets (failed) on the end of its subject:

From: root (Cron Daemon)
To: [email protected],[email protected]
Subject: Cron <root@web1> echo "b: two addresses"; exit 3 (failed)
X-Cron-Env: <[email protected],[email protected]>

At the default level the subject is the same without the suffix; we checked both on Debian 13 and Ubuntu 26.04. With it on, a mail filter on (failed) gives you failure-only mail, for jobs that print something when they fail. cronie never adds it. BusyBox sends Subject: cron: <command> and no other headers.

MAILTO="" turns mail off on Debian, Ubuntu and cronie: no mail, no log line. On BusyBox it doesn’t. crond passed To: "" to sendmail, quotes included. Leave MAILTO out entirely there.

Where it goes, distro by distro

Debian: /var/mail/mail, not /var/mail/root

On Debian 13, cron Recommends default-mta, so apt install cron brings in exim4 and bsd-mailx. exim’s default answer to “how should mail be delivered” is local only. After a minute of our crontab:

# ls -l /var/mail/
-rw-rw---- 1 deploy mail  812 Nov 17 17:46 deploy
-rw------- 1 mail   mail 2841 Nov 17 17:46 mail
# mail
No mail for root

The deploy user’s cron mail is where you’d expect. Root’s isn’t in /var/mail/root, because Debian’s exim config never delivers as root: a router named mail4root writes root’s mail to /var/mail/mail instead. The job that set [email protected] went nowhere useful either:

=> /var/mail/mail <root@web1> R=mail4root T=address_file
** [email protected] R=nonlocal: Mailing to remote domains not supported

The bounce for it is in /var/mail/mail too. Read it with mail -f /var/mail/mail.

To send root’s mail to a person on the same box, add a line to /etc/aliases:

root: deploy

exim reads that file on every delivery, so there’s nothing to reload. The next run went to /var/mail/deploy. To reach an outside address, either run dpkg-reconfigure exim4-config and pick “mail sent by smarthost”, or replace exim with msmtp (below). apt install msmtp-mta removes exim, since both provide mail-transport-agent.

Ubuntu and containers: discarded

Ubuntu 26.04’s cron package only Suggests a mail server, and the official debian and ubuntu images don’t have one. Cron logs the “No MTA installed” line once per run that printed something and throws the output away. The cron logs post covers where that line ends up when there’s no syslog daemon either. In a container, the Docker cron post is the better fix than a mail server.

Fedora and RHEL: syslog, until a mail server shows up

With no /usr/sbin/sendmail, cronie writes every output line to syslog as CMDOUT, which is actually the most useful default of the four. Install Postfix for some other reason, and the same output moves into local mailboxes without a word. If you want it in the log either way, add -s to CRONDARGS in /etc/sysconfig/crond.

cronie also does something that matters once you add a relay: it calls sendmail -FCronDaemon -i -odi -oem -oi -t -f root. That -f root is the envelope sender, and it’s just the crontab owner’s name, no domain. More on that below.

Alpine: lost on port 25

On Alpine, /usr/sbin/sendmail is a symlink to BusyBox. Its sendmail doesn’t queue anything; it opens an SMTP connection to 127.0.0.1:25. With MAILTO set and nothing listening:

crond: child running sendmail
sendmail: can't connect to remote host (127.0.0.1): Connection refused

That line goes to crond’s stderr, which under OpenRC is /dev/null. Without MAILTO, BusyBox writes the output to crond’s stdout, which is fine in a container running crond -f and gone otherwise. The fix is the same as on Debian: apk add msmtp and point the /usr/sbin/sendmail symlink at /usr/bin/msmtp. BusyBox calls it with -ti, which msmtp understands.

Getting it to a real inbox with msmtp

msmtp is a small sendmail replacement that forwards each message to an SMTP server you name. No queue, no daemon, nothing listening. On Debian and Ubuntu:

apt install msmtp-mta

It installs /usr/sbin/sendmail and no config. This is the config that worked against our test relay, with the lines you’ll want for a real one:

# /etc/msmtprc
defaults
auth            on
tls             on
tls_trust_file  /etc/ssl/certs/ca-certificates.crt
syslog          LOG_MAIL
aliases         /etc/aliases

account relay
host            smtp.example.com
port            587
user            [email protected]
password        app-password-here
from            [email protected]
set_from_header on
allow_from_override off

account default : relay
# /etc/aliases
root: [email protected]
default: [email protected]

Every line after host fixed a failure we hit. In the order we hit them:

No config at all. msmtp exits 78 and cron logs got status 0x004e from MTA. The mail is dropped.

No aliases. Without MAILTO, Debian’s cron mails root: just the word, passed on the command line. msmtp sends RCPT TO:<root> and the relay refuses it:

msmtp: recipients=root smtpstatus=553 smtpmsg='553 5.1.3 <root>: recipient address needs a domain' exitcode=EX_DATAERR

The aliases file maps root to an address, and default: catches every other local user.

No set_from_header. Debian’s cron writes From: root (Cron Daemon), with no domain. Even when the relay takes it, a provider checking SPF and DMARC has nothing to check it against, and that’s how cron mail ends up in spam. set_from_header on rewrites it to CronDaemon <[email protected]>. You can also set [email protected] in the crontab; Debian 13’s cron and cronie both honour it.

cronie’s -f root. msmtp takes -f as the envelope sender over its own from line, so on Fedora the relay saw MAIL FROM:<root> and refused it with exit 65. allow_from_override off makes msmtp keep the from you configured.

No syslog. msmtp logs nothing by default. With syslog LOG_MAIL, each attempt leaves one line with the relay’s answer, which is the only record you’ll have.

A comma-separated [email protected],[email protected] went to both addresses through msmtp.

One permission catch: cron runs sendmail as the crontab’s owner. We checked with a stub sendmail that logged its user, and both Debian’s cron and cronie ran it as deploy for deploy’s crontab. So /etc/msmtprc has to be readable by every user whose crontab sends mail, password included. If only root has a crontab, chmod 600 is fine. Otherwise use a relay account that can only send, or passwordeval to read the password from somewhere those users can’t touch.

Then test it the way cron will use it, not with a fresh terminal:

printf 'Subject: cron mail test\n\nit works\n' | /usr/sbin/sendmail root

Is MAILTO worth fixing?

Sometimes. If you have a handful of jobs that print only when something is wrong, working MAILTO plus chronic from moreutils is a decent setup and costs nothing:

[email protected]
0 3 * * * chronic /usr/local/bin/backup.sh

chronic hides the output unless the command exits non-zero, which turns “mail on output” into “mail on failure”. How to get alerted when a cron job fails covers that and the other options, including the part MAILTO can never do: telling you a job didn’t run at all. On a systemd box, OnFailure= does the same job for timers.

RunWisp (our project) is an open-source cron replacement that ships as a single binary, and it inverts cron’s rule: it mails when a run fails, times out or is missed, once more when the task recovers, and stays quiet for ordinary successful runs. Its sendmail notifier uses the msmtp you just set up:

[notifiers.mta]
type = "sendmail"
from = "[email protected]"
to   = ["[email protected]"]

[tasks.backup]
cron   = "0 3 * * *"
run    = "/usr/local/bin/backup.sh"
notify = ["mta"]

We ran RunWisp 1.10.0 against the same test relay with one task that failed and one that printed all good. Only the failure was mailed:

From: [email protected]
To: [email protected]
Subject: backup failed

backup failed

Exited with code 1 after 0.0s.

Scheduled run · 17 Nov, 17:55.

pg_dump: error: connection to server failed

--
from runwisp · white-wave

The From is msmtp’s, because of set_from_header on. There’s also an smtp notifier that talks to a relay directly if you’d rather not install msmtp, and runwisp import cron turns a crontab’s MAILTO= into the notifier block above. The trade-off is the one cron users usually want: a job that succeeds while printing a warning no longer mails you. Add a route for succeeded runs if you relied on that. And like anything on the box, it can’t mail you when the box itself is down.

Whichever you pick, break a job on purpose and check the mail arrives. On Debian, that check is what tells you the last six months of cron mail are in /var/mail/mail.

Common questions

Why is cron MAILTO not sending email?
Cron only mails when the job prints something, and it hands the mail to /usr/sbin/sendmail. If nothing is installed there, Debian and Ubuntu throw the output away and log 'No MTA installed, discarding output'. If Debian's default exim is there, it only delivers locally, so mail to an outside address bounces into /var/mail/mail. Install msmtp-mta, point it at an SMTP relay, add a root alias and a from address, and MAILTO mail reaches your inbox.
Where does cron send mail by default?
To the crontab's owner on the local machine, through /usr/sbin/sendmail. On Debian 13, where installing cron pulls in exim, a regular user's mail lands in /var/mail/<user> and root's lands in /var/mail/mail, because exim won't deliver as root. Without a mail server it's discarded (Debian, Ubuntu), written to syslog (cronie on Fedora and RHEL), or printed to crond's stdout (BusyBox on Alpine).
Why does mail say 'No mail for root' when cron sent root mail on Debian?
Debian's exim config never delivers as root. A router called mail4root sends root's mail to /var/mail/mail instead, so /var/mail/root stays empty. Read it with mail -f /var/mail/mail, or add root: yourname to /etc/aliases so root's mail goes to a real account from then on.
How do I make cron email me only when a job fails?
Cron mails on output, not on exit status, so a job that fails without printing sends nothing and a chatty job that succeeds sends mail every time. Wrap the command in chronic from moreutils: it swallows the output unless the command exits non-zero. On Debian and Ubuntu, starting cron with -L 5 (EXTRA_OPTS in /etc/default/cron) also adds '(failed)' to the subject of a failed job's mail, which a mail filter can match.
How do I stop cron from sending emails?
Put MAILTO="" above the job on Debian, Ubuntu and cronie; nothing is mailed or logged for it. On Alpine's BusyBox crond, MAILTO="" doesn't work: it tries to mail an address that is literally two quote marks. Leave MAILTO out there, or send the output to a file with >> /var/log/job.log 2>&1, which works everywhere.
Is there a cron replacement that emails me when a job fails instead of when it prints?
RunWisp, an open-source cron replacement that ships as a single binary, has a sendmail notifier that uses the same msmtp or Postfix setup cron uses, and an SMTP notifier that talks to a relay directly. It mails when a run fails, times out or is missed, with the exit code and the last lines of output, sends one more when the task recovers, and stays quiet for ordinary successful runs unless you ask for those too. runwisp import cron turns a crontab's MAILTO into the notifier block. It runs on one host, so it can't email you that the host itself is down.
  1. PM2 cron_restart runs the script immediately: how to stop it

    pm2 start --cron runs your job the moment you start it and again on every reload. We tested PM2 7.1.2 and found three ways to run it only at the cron time.

  2. What happens when a cron job takes longer than its interval

    We ran jobs longer than their interval under cron, cronie, systemd timers, supervisord and RunWisp. cron stacks copies; systemd runs them back to back.

Get started
GPL 3.0 · no accounts · free to self-host

Start in 30 seconds. Ship on your terms.

A single Go binary. If it doesn't earn the disk space, rm it. No account, no signup, no catch.

Install in 30 seconds
curl -fsSL https://get.runwisp.com | sh