请问有人知道如何在使用邮件命令发送电子邮件时更改发件人用户吗? 我已经查看了手册,但没有找到如何执行此操作的方法。
我们正在运行Redhat Linux 5。
你可以使用 -a 来指定任何需要的额外头部信息。
$mail -s "Some random subject" -a "From: some@mail.tld" to@mail.tld
/etc/alternatives/mail -> /usr/bin/bsd-mailx
),但不适用于16.04(/etc/alternatives/mail -> /usr/bin/s-nail
)。 - Phillip -Zyan K Lee- Stockmannmailutils
之后可正常使用。 - Gogowitschhttp://www.mindspill.org/962 似乎有一个解决方案。
基本上:
echo "这是邮件的主体内容" | mail -s "邮件主题" recipent_address@example.com -- -f from_user@example.com
--
标记了 getopt(3)
的选项结束,所以在 --
后面 -f
怎么可能作为一个选项工作呢?同时,在 Ubuntu 上阅读(bsd)mail
的手册没有提到任何支持 -f
参数的内容。最后,在 Ubuntu 14.04 上进行测试(有些难以置信和微弱的希望),事实证明它确实无法工作。值得一提的是(难以再次相信),原始 mindspill.org 的 URL 表示它可以在 Red Hat 上工作,但并未指定版本。 - arielf-v
选项进行详细输出 mail -v -s ...
。如果邮件发送失败,例如由于未正确配置的邮件服务器,则smtp命令日志将显示出错原因。 - Andrei Krasutskimail -r from@from.from -R from@from.com
-r = 发信地址 -R = 回复地址
作者指出他的版本的 mail 不支持这个标志。但如果你有一个支持这个标志的版本,那么它可以正常工作。
在使用SMTP发送邮件时,mail
命令建议设置from
变量的方法如下(在CentOS 6上测试通过):
当发送电子邮件时,使用mail
命令设置from
变量可以指定发件人。以下是在CentOS 6上测试通过的设置方式:
mail -s Subject -S from=sender@example.com recipient@example.com
您也可以使用-a
选项附加文件:
mail -s Subject -S from=sender@example.com -a path_to_attachement recipient@example.com
我尝试了这些方法都没有成功(Ubuntu 12.04),但是通过不断尝试,我最终找到了解决办法:
echo 'my message blabla\nSecond line (optional of course)' |
mail -s "Your message title"
-r 'Your full name<yourSenderAdress@yourDomain.abc>'
-Sreplyto="yourReplyAdressIfDifferent@domain.abc"
destinatorEmail@destDomain.abc[,otherDestinator@otherDomain.abc]
我得到了以下邮件命令:
apt-get install mailutils
你可以在邮件命令的末尾添加sendmail选项,首先要添加--。-f是在sendmail上设置发件人地址的命令。因此,您可以这样做:
mail recipient@foo.com -- -f sender@bar.com
上述方法都对我无效,我花了很长时间才弄清楚,希望这能帮助下一个人。
我正在使用Ubuntu 12.04 LTS和mailutils v2.1。
我在网上找到了这个解决方案,不知道在哪里,也找不到了:
-aFrom:Servername-Server@mydomain.com
完整的命令如下:
cat /root/Reports/ServerName-Report-$DATE.txt | mail -s "Server-Name-Report-$DATE" myemailadress@mydomain.com -aFrom:Servername-Server@mydomain.com
echo "test" | mail -s "a test" me@noone.com
相关日志如下:
Feb 6 09:02:51 myserver postfix/qmgr[28875]: B10322269D: from=<root@myserver.com>, size=437, nrcpt=1 (queue active)
Feb 6 09:02:52 myserver postfix/smtp[19848]: B10322269D: to=<me@noone.com>, relay=myMTA[x.x.x.x]:25, delay=0.34, delays=0.1/0/0.11/0.13, dsn=2.0.0, status=sent (250 Ok 0000014b5f678593-a0e399ef-a801-4655-ad6b-19864a220f38-000000)
试图使用以下命令更改发件人地址--
echo "test" | mail -s "a test" me@noone.com -- dude@thisguy.com
这会更改orig-to的值,但不会更改from的值:
Feb 6 09:09:09 myserver postfix/qmgr[28875]: 6BD362269D: from=<root@myserver.com>, size=474, nrcpt=2 (queue active)
Feb 6 09:09:09 myserver postfix/smtp[20505]: 6BD362269D: to=<me@noone>, orig_to=<dude@thisguy.com>, relay=myMTA[x.x.x.x]:25, delay=0.31, delays=0.06/0/0.09/0.15, dsn=2.0.0, status=sent (250 Ok 0000014b5f6d48e2-a98b70be-fb02-44e0-8eb3-e4f5b1820265-000000)
接下来尝试使用-r和--调整from和orig-to。
echo "test" | mail -s "a test" -r dude@comeguy.com me@noone.com -- dude@someguy.com
日志如下:
Feb 6 09:17:11 myserver postfix/qmgr[28875]: E3B972264C: from=<dude@someguy.com>, size=459, nrcpt=2 (queue active)
Feb 6 09:17:11 myserver postfix/smtp[21559]: E3B972264C: to=<me@noone.com>, orig_to=<dude@someguy.com>, relay=myMTA[x.x.x.x]:25, delay=1.1, delays=0.56/0.24/0.11/0.17, dsn=2.0.0, status=sent (250 Ok 0000014b5f74a2c0-c06709f0-4e8d-4d7e-9abf-dbcea2bee2ea-000000)
这是我使用的方法,希望能对某些人有所帮助。
这里有一个解决方案。
在-r之后,第二个最简单的解决方案是指定一个From:头,并通过换行符将其与正文分开,就像这样
$mail -s "Subject" destination@example.com
From: Joel <joel@example.com>
Hi!
.
只在少数邮件版本中工作,不知道Redhat搭载的是哪个版本)。
附注:大多数邮件版本都很糟糕!