Cron only sends email when in the test mode

My cron service only sends email when in test mode. I can confirm this by running the service interactively:

root:~# crond -n -x bit,test -m 'sendmail'
debug flags enabled: test bit
[25625] cron started
log_it: (CRON 25625) STARTUP (1.7.2)
log_it: (CRON 25625) INFO (RANDOM_DELAY will be scaled with factor 47% if used.)
log_it: (CRON 25625) INFO (running with inotify support)
log_it: ((null) 25625) Unauthorized SELinux context=unconfined_u:unconfined_r:unconfined_t:s0 file_context=system_u:object_r:system_cron_spool_t:s0 (/etc/crontab)
log_it: ((null) 25625) SELinux in permissive mode, continuing (/etc/crontab)
log_it: ((null) 25625) Unauthorized SELinux context=unconfined_u:unconfined_r:unconfined_t:s0 file_context=system_u:object_r:system_cron_spool_t:s0 (/etc/cron.d/0hourly)
log_it: ((null) 25625) SELinux in permissive mode, continuing (/etc/cron.d/0hourly)
log_it: (CRON 25625) INFO (@reboot jobs will be run at computer's startup.)
log_it: (root 25628) CMD (echo "This is a CRON test" > /tmp/crontest.txt)
sendmail: No recipients supplied - mail will not be sent        
log_it: (root 25626) CMDEND (echo "This is a CRON test" > /tmp/crontest.txt)
^Clog_it: (CRON 25625) INFO (Shutting down)

Notice that with this set of flags, crond complains that sendmail is missing a recipient. And if I modify the flag to -m ‘sendmail -t’, I will receive an email.

But if I run it without the test flag, the error message does not appear, indicating that the sendmail command was not executed at all.

root:~# crond -n -x bit -m 'sendmail'
debug flags enabled: bit
[25630] cron started
log_it: (CRON 25630) STARTUP (1.7.2)
log_it: (CRON 25630) INFO (RANDOM_DELAY will be scaled with factor 66% if used.)
log_it: (CRON 25630) INFO (running with inotify support)
log_it: ((null) 25630) Unauthorized SELinux context=unconfined_u:unconfined_r:unconfined_t:s0 file_context=system_u:object_r:system_cron_spool_t:s0 (/etc/crontab)
log_it: ((null) 25630) SELinux in permissive mode, continuing (/etc/crontab)
log_it: ((null) 25630) Unauthorized SELinux context=unconfined_u:unconfined_r:unconfined_t:s0 file_context=system_u:object_r:system_cron_spool_t:s0 (/etc/cron.d/0hourly)
log_it: ((null) 25630) SELinux in permissive mode, continuing (/etc/cron.d/0hourly)
log_it: (CRON 25630) INFO (@reboot jobs will be run at computer's startup.)
log_it: (root 25635) CMD (echo "This is a CRON test" > /tmp/crontest.txt)
log_it: (root 25632) CMDEND (echo "This is a CRON test" > /tmp/crontest.txt)
^Clog_it: (CRON 25630) INFO (Shutting down)

Does anyone know what is causing the behaviour?

Thanks.

Installation:
6.16.12-200.fc42.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Oct 12 16:31:16 UTC 2025 x86_64 GNU/Linux
ssmtp-2.64-39.fc42.x86_64
cronie-anacron-1.7.2-6.fc42.x86_64
cronie-1.7.2-6.fc42.x86_64

I would first ensure that the fully qualified path to sendmail is used. Should be in /usr/bin if memory serves.

I actually tried calling a script instead of sendmail, so something like this:

root:~# cat /root/sm.sh
#!/bin/bash
echo "$*" > /tmp/sm.txt
echo "$(cat)" >> /tmp/sm.txt

root:~# crond -n -x bit,test -m '/root/sm.sh'
debug flags enabled: test bit
[26178] cron started
log_it: (CRON 26178) STARTUP (1.7.2)
log_it: (CRON 26178) INFO (RANDOM_DELAY will be scaled with factor 27% if used.)
log_it: (CRON 26178) INFO (running with inotify support)
log_it: ((null) 26178) Unauthorized SELinux context=unconfined_u:unconfined_r:unconfined_t:s0 file_context=system_u:object_r:system_cron_spool_t:s0 (/etc/crontab)
log_it: ((null) 26178) SELinux in permissive mode, continuing (/etc/crontab)
log_it: ((null) 26178) Unauthorized SELinux context=unconfined_u:unconfined_r:unconfined_t:s0 file_context=system_u:object_r:system_cron_spool_t:s0 (/etc/cron.d/0hourly)
log_it: ((null) 26178) SELinux in permissive mode, continuing (/etc/cron.d/0hourly)
log_it: (CRON 26178) INFO (@reboot jobs will be run at computer's startup.)
log_it: (root 26181) CMD (echo "This is a CRON test" > /tmp/crontest.txt)
log_it: (root 26179) CMDEND (echo "This is a CRON test" > /tmp/crontest.txt)
^Clog_it: (CRON 26178) INFO (Shutting down)

root:~# ls  -lta /tmp/sm.txt
-rw-r--r--. 1 root root 603 Nov 22 19:07 /tmp/sm.txt

So you can see, the file is being created.

But without the test flag, this file will not be created. So even with a fully qualified path, it seems cron is not executing the script.

It appears piping the output to a text file would prevent cron from sending emails. Because if I change my crontab from

* * * * * echo "This is a CRON test" > /tmp/crontest.txt

to

* * * * * echo "This is a CRON test"

cron sends email.

How does this explain the initial problem you had where you were not using a crontab entry, but calling the sendmail command directly?

The -m flag doesn’t override the crontab: it means “use the following command to send mail when necessary”, rather than “run the following command as the ‘payload’, instead of the commands in the crontab”.

Ah - I assumed the op was trying to send mail using crontab, rather than using it as a reporting mechanism.

Right. I think the ‘real’ problem is one step back from the one described in the thread title: it’s more like “in non-test mode, the tasks executed by cron don’t generate any output that needs to be emailed” than “in non-test mode, cron tries but fails to send a mail”.

Yes, exactly. Only output written to stdout and stderr (and not redirected) gets emailed.

I realized that it may be related to stdout or stderr when I looked at the email itself. The email is not giving me the output of the command but instead its cron telling me that it is not exec’ing the command.

debug DTEST is on, not exec'ing command.
	cmd='echo "This is a CRON test" > /tmp/crontest.txt' shell='/bin/sh'