使用邮件命令发送电子邮件时,需指定发件人

70

请问有人知道如何在使用邮件命令发送电子邮件时更改发件人用户吗? 我已经查看了手册,但没有找到如何执行此操作的方法。

我们正在运行Redhat Linux 5。


已删除“重复”标签。我认为不鼓励使用此标签。 - Paolo Bergantino
7
你可能会更快地得到这个问题的答案,只需键入“man mail”,它将显示该命令的手册。 - Ludvig A. Norin
-r from@address.com - RHEL7 FYI - Neil Gaetano Lindberg
15个回答

1
对于CentOS,以下是有效的命令:

mail -s Subject -S from=sender@example.com recipient@example.com

1
echo "This is the main body of the mail" | mail -s "Subject of the Email" recipent_address@example.com -- -f from_user@example.com -F "Elvis Presley"

或者

echo "This is the main body of the mail" | mail -s "Subject of the Email" recipent_address@example.com -aFrom:"Elvis Presley<from_user@example.com>"

1

这适用于Centos7

echo "这是邮件的主体内容" | mail -s "邮件主题" -r 发件人地址@whatever.com 收件人地址@example.com


1
-r 显示名称<发送者地址@whatever.com> - Nick Dong

1

以下是一篇来自2018年的答案,针对Debian 9 stretch系统。

请注意使用-e参数以允许换行符在echo中显示,并使用-r参数使mailx能够在发送电子邮件地址时显示名称:

$ echo -e "testing email via yourisp.com from command line\n\nsent on: $(date)" | mailx -r "Foghorn Leghorn <sender@yourisp.com>" -s "test cli email $(date)" -- recipient@somedomain.com

希望这有所帮助!

0

感谢所有提供示例的人,有些对我有效,有些则不是。 以下是另一个对我有效的简单示例格式。

echo "Sample body" | mail -s "Test email" from=sender-addrs@example.com recepient-addres@example.com

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接