我设置ssmtp将电子邮件从我的Ubuntu服务器发送到外部电子邮件地址。
使用mailutils包的mail命令,我可以从服务器接收通过以下方式发送的电子邮件:
$echo test | mail -s test remote@mydomain.com我现在要做的是,向remote@mydomain.com发送任何发送给用户根的消息(如警报等)。
$echo test | mail -s test root到目前为止,我发现的最混乱的解决方案之一是:
由于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 remote@mydomain.com (221 2.0.0 Bye) uid=0 username=root outbytes=459到目前为止的总结。现在来问这个问题:
如何设置ssmtp和mail以便
$echo test | mail -s test root是否成功地将发送到root的电子邮件发送到root的别名?
发布于 2021-12-27 19:12:07
这是为我准备好的,答案在如何使ssmtp将本地用户映射到To:字段的电子邮件地址
总之,问题在于我使用的是mailutils包。切换到bsd-mailx (它也提供/usr/bin/mail)允许我自定义/etc/mail.rc以将To地址映射到alias root root
一些进一步的背景:
我的目标是使用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:
Received: from gmail.com ([MY-IP-ADDRESS-REDACTED])
by smtp.gmail.com with ESMTPSA id az14sm13499775qkb.97.2021.12.27.06.12.13
for
(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
X-Google-Original-From: "root"
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:
X-Mailer: mail (GNU Mailutils 3.7)
test因此,很明显,谷歌接受了这封电子邮件,然后试图发送到不存在的root@server.lan。相反,Fastmail在接收电子邮件之前检查收件人地址是更明智的做法,从而避免了产生反弹的需要。我只是希望他们的错误信息是清晰的,并记录在某处!
有了上述内容之后,我现在得到以下标题(通过在zfs scrub池上运行一个zfs在完成后发送电子邮件的池中触发):
From: "root"
Date: Mon, 27 Dec 2021 09:24:06 -0500
To: root
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: https://askubuntu.com/questions/1228606
复制相似问题