This was fixed for me with the answer at How to get ssmtp to map local user to email address for the To: field
In summary, the problem was that I was using the mailutils
package. Switching to bsd-mailx
(which also provides /usr/bin/mail
) allowed for me to customize /etc/mail.rc
to map the To
address with alias root root<me@example.com>
Some further context:
My goal was to do the above using Fastmail as my SMTP server, sending to my own Fastmail account. When running echo 'test' | mail -s "Test" root
, I would see the following in the ssmtp logs:
$ sudo journalctl -t sSMTP -f
Dec 26 21:20:55 server.lan sSMTP[3898845]: Creating SSL connection to host
Dec 26 21:20:55 server.lan sSMTP[3898845]: SSL connection using ECDHE_RSA_AES_256_GCM_SHA384
Dec 26 21:20:56 server.lan sSMTP[3898845]: 551 5.7.1 Not authorised to send from this header address
I couldn't find anything useful for that specific error Fastmail was returning. To troubleshoot, I tried switching to a gmail account. In that case, Google accepted my email, and it was visible in my user's "sent" messages, but I quickly got a bounce message:
DNS Error: 13562819 DNS type 'mx' lookup of server.lan responded with code NXDOMAIN Domain name not found: server.lan
And, looking at the message source:
Return-Path: <example@gmail.com>
Received: from gmail.com ([MY-IP-ADDRESS-REDACTED])
by smtp.gmail.com with ESMTPSA id az14sm13499775qkb.97.2021.12.27.06.12.13
for <root@server.lan>
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Mon, 27 Dec 2021 06:12:14 -0800 (PST)
Message-ID: <61c9c9be.1c69fb81.e5f1.caae@mx.google.com>
From: root <example@gmail.com>
X-Google-Original-From: "root" <root@gmail.com>
Received: by gmail.com (sSMTP sendmail emulation); Mon, 27 Dec 2021 09:12:12 -0500
Date: Mon, 27 Dec 2021 09:12:12 -0500
To: <root@server.lan>
X-Mailer: mail (GNU Mailutils 3.7)
test
So, clearly Google was accepting the email, then trying to send to root@server.lan
which didn't exist. In contrast, Fastmail does the smarter thing of checking the To address before accepting the email, avoiding the need to generate a bounce. I just wish their error message was clearer and documented somewhere!
With the above in place, I now get the following headers (triggered by running a zfs scrub
on a pool where zfs sends emails on completion):
From: "root" <root@example.com>
Date: Mon, 27 Dec 2021 09:24:06 -0500
To: root<andrew@example.com>
Subject: ZFS scrub_finish event for bpool on fileserver.lan
MIME-Version: 1.0
Content-Type: text/plain; charset="ANSI_X3.4-1968"
Content-Transfer-Encoding: 8bit
Message-ID: <cmu-lmtpd-1817460-1640615049-2@sloti47n08>
root
user of the system that it is on? If so, it is justecho test | mail -s test root@localhost
– Terrance Apr 19 '20 at 18:20echo test | mail -s test root@localhost
results inApr 19 20:22:58 hostname sSMTP[1270]: RCPT TO:<root@localhost> (504 5.5.2 <root@localhost>: Recipient address rejected: need fully-qualified address)
– marcas756 Apr 19 '20 at 18:24myorigin
of/etc/postfix/main.cf
is not configured properly – Terrance Apr 19 '20 at 18:27