SMTP Header Rewrite

TLDR: SMTP header is being incorrectly rewritten and trying to find solution.

Ubuntu Version: 26.04 LTS Server
Desktop Environment (if applicable): N/A

I have a fully updated version of Ubuntu Server and am having issues with system email notifications, specifically cron STDERR/STDOUT. I have the latest versions of mutt & msmtp installed and configured (Postfix/Exim is overkill for my situation). When sending an email from CLI (via mutt or mail, which mail is symlinked to mutt), the email is received with proper headers. However, when I receive an email from the cron daemon (I have crontab configured with proper MAILTO=), the email header has the “From” as “Cron Daemon <root@{mailhost}>” where mailhost is my webhost/email provider–NOT the local server in my house running the cron job. I have /etc/aliases configured with the correct “from” address for sendmail (symlinked to msmtp) to use for cron yet it appears to come from my webhost’s cron daemon, not mine. I have two other Ubuntu servers with similar setup that don’t have this issue, though they are 24.04.4 not latest LTS. I am truly perplexed that the header is rewritten before it even reaches the email host (NOTE: the “from” shows the webhost/mail host but the correct “reply to” in the header in the first transaction).

I’ve tried wrapper scripts to replace low-level cron email output but they don’t work. As previously stated, no issues with sending direct from CLI. Just can’t understand how/why header is rewritten with webhost/email provider when cron is sending STDERR/STDOUT from a local server (I sort/search email based on cron output).

Example header:

Received: from {ISP name/IP}:49260 helo=localhost)
	by {webhost/email provider} with esmtpsa  (TLS1.3) tls TLS_AES_256_GCM_SHA384
	(Exim 4.99.5)
	(envelope-from <{correct from email, as in /etc/aliases}>)
	id 1wsVOv-0000000DsVM-2wV1
	for {correct delivery email};
	Fri, 07 Aug 2026 20:59:01 -0400
Date: Fri, 07 Aug 2026 18:59:01 -0600
Message-ID: <2e664fc05740ae513329dab3b80ba915@{my domain}>
From: root@{webhost/email provider} (Cron Daemon)
To: {correct delivery email}
Subject: Cron <root@{local server hostname}>   /root/scripts/cron_test.sh
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <MAILTO={correct email>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <LOGNAME=root>

+++ cron test completed +++

While this isn’t a significant issue, it does present some challanges as the “From” sorting gets mixed up and/or combined.

Thanks in advance for any insight!

MAILTO is irrelevant in this case, you have issues with sender, not recipient. You need to set MAILFROM to define the sender address, otherwise cron is using unqualified root (Cron Daemon) and your mailhost adds domain when processing it.

See man cron:

       cron then wakes up every minute, examining all stored crontabs, checking each command
       to see if it should be run in the current minute.  When executing commands, any  out‐
       put  is  mailed to the owner of the crontab (or to the user named in the MAILTO envi‐
       ronment variable in the crontab, if such exists) from the owner of  the  crontab  (or
       from  the email address given in the MAILFROM environment variable in the crontab, if
       such exists).  The children copies of cron running these processes  have  their  name
       coerced to uppercase, as will be seen in the syslog and ps output.
1 Like

I had looked in man pages and didn’t see the MAILFROM option. But I tested it and it worked.

Thanks for your help!

1 Like

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.