如何使用 mailutils 更改发件人姓名?

如何使用 mailutils 更改发件人姓名?

我有一个脚本,可以定期发送包含一些服务器信息的电子邮件。我在脚本中使用以下命令

cat $msg |mail -r [email protected] -s "server event" [email protected]

Ubuntu 机器的问题是它们总是放入FROM 标题,所以当我收到电子邮件时它只显示来自"root <[email protected]>"
由于我有许多不同的机器,我希望看到电子邮件地址。在Fedora使用相同命令可以正常工作,并且电子邮件仅包含电子邮件地址From header
我尝试使用 (给出错误)或 但结果相同。将名称“root”附加到发件人标题,因此我只看到来自 root 的电子邮件。-r Script1 <[email protected]>-u Script1 -r [email protected]mail

答案1

当我把所有内容放在一行时,我发现了一个解决方案:

cat $msg |mail -a "From: Script1 <[email protected]>" -s "server event" [email protected]

但是如果我使用变量作为From:字段,它会一直给我一个错误。

msg="Message to send"
EMTO="[email protected]"
EMFR='-a "From: Script1 <[email protected]>"'
cat $msg |mail $EMFR -s "server event" $EMTO

mail: Cannot parse address `<[email protected]>"' (while expanding `<[email protected]>"'): Malformed email address

我能找到的最接近的工作选项是定义电子邮件,如下所示:

msg="Message to send"
EMTO="[email protected]"
EMFR="Script1 <[email protected]>"
cat $msg |mail -a "From: $EMFR" -s "server event" $EMTO

我想避免修改mail命令,因为每个脚本中都有很多命令,而email addresses命令只在顶部定义。有什么线索吗?

相关内容