sSMTP、邮件、别名

sSMTP、邮件、别名

我设置了 ssmtp 来将电子邮件从我的 Ubuntu 服务器发送到外部电子邮件地址。

使用 mailutils 包的 mail 命令,我能够接收通过以下方式从我的服务器发送的电子邮件:

$echo test | mail -s test [email protected]

我现在想要做的是将任何发送给用户 root 的消息(如警报等)发送到[电子邮件保护]

$echo test | mail -s test root

到目前为止我发现的最有希望的解决方案之一是:

sSMTP 重新别名、别名和 mail.rc

由于 ssmtp 无法转发和别名,本文建议使用邮件别名地址。但这也不起作用。事实上,我的文件系统中甚至没有 /etc/mail.rc 文件。

看起来好像电子邮件已经离开了主机,但从未到达远程邮件地址。

Apr 19 19:46:16 hostname sSMTP[1160]: Creating SSL connection to host
Apr 19 19:46:16 hostname sSMTP[1160]: SSL connection using ECDHE_RSA_AES_256_GCM_SHA384
Apr 19 19:46:17 hostname sSMTP[1160]: Sent mail for [email protected] (221 2.0.0 Bye) uid=0 username=root outbytes=459

到目前为止,总结如下。现在来回答问题:

如何设置 ssmtp 和邮件以便

$echo test | mail -s test root

将成功发送一封发送给 root 的电子邮件到 root 的别名吗?

答案1

这个问题已经为我解决了,答案是如何让 ssmtp 将本地用户映射到收件人:字段的电子邮件地址

总之,问题在于我使用了mailutils包。切换到bsd-mailx(也提供/usr/bin/mail)允许我自定义/etc/mail.rc映射To地址alias root root<[email protected]>

进一步了解一下背景信息:

我的目标是使用 Fastmail 作为我的 SMTP 服务器来执行上述操作,并发送到我自己的 Fastmail 帐户。运行时echo 'test' | mail -s "Test" root,我会在 ssmtp 日志中看到以下内容:

$ 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

我找不到任何有用的信息来解释 Fastmail 返回的那个特定错误。为了解决问题,我尝试切换到 Gmail 帐户。在这种情况下,Google 接受了我的电子邮件,并且它在我的用户的“已发送”消息中可见,但我很快就收到了退回消息:

DNS Error: 13562819 DNS type 'mx' lookup of server.lan responded with code NXDOMAIN Domain name not found: server.lan 

并且,查看消息来源:

Return-Path: <[email protected]>
Received: from gmail.com ([MY-IP-ADDRESS-REDACTED])
        by smtp.gmail.com with ESMTPSA id az14sm13499775qkb.97.2021.12.27.06.12.13
        for <[email protected]>
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Mon, 27 Dec 2021 06:12:14 -0800 (PST)
Message-ID: <[email protected]>
From: root <[email protected]>
X-Google-Original-From: "root" <[email protected]>
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: <[email protected]>
X-Mailer: mail (GNU Mailutils 3.7)

test

因此,很明显 Google 接受了电子邮件,然后尝试发送到[email protected]不存在的地址。相比之下,Fastmail 更聪明,会检查收件人地址接受电子邮件,避免产生退回邮件。我只是希望他们的错误消息更清晰,并记录在某处!

有了上述内容,我现在得到了以下标题(通过zfs scrub在 zfs 在完成时发送电子邮件的池上运行触发):

From: "root" <[email protected]>
Date: Mon, 27 Dec 2021 09:24:06 -0500
To: root<[email protected]>
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>

相关内容