使用mail命令发送邮件时指定发件人用户
有谁知道使用 mail 命令发送电子邮件时如何更改发件人用户? 我浏览了手册页,但不知道如何执行此操作。
我们正在运行 Redhat Linux 5。
Does anyone know how to change the from user when sending email using the mail command? I have looked through the man page and can not see how to do this.
We are running Redhat Linux 5.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
mail -r [电子邮件受保护] -R [电子邮件受保护]
-r = from-addr
-R = 回复地址
作者已表明他的邮件版本不支持此标志。 但如果你有一个版本可以正常工作。
mail -r [email protected] -R [email protected]
-r = from-addr
-R = reply-to addr
The author has indicated his version of mail doesn't support this flag. But if you have a version that does this works fine.
您可以使用 -a 指定您可能需要的任何额外标头
You can specify any extra header you may need with -a
http://www.mindspill.org/962 似乎有一个解决方案。
本质上:
echo“这是邮件的主体”| mail -s "电子邮件主题" [电子邮件受保护] -- - f [电子邮件受保护]
http://www.mindspill.org/962 seems to have a solution.
Essentially:
echo "This is the main body of the mail" | mail -s "Subject of the Email" [email protected] -- -f [email protected]
通过 SMTP 发送时,
mail
手册页建议设置from
变量,这样(在 CentOS 6 上测试):您还可以使用
附加文件>-a
选项:When sending over SMTP, the
mail
man page advises to set thefrom
variable, in this way (Tested on CentOS 6):You could also attach a file using the
-a
option:这些都不适合我(Ubuntu 12.04),但最终经过试用& 我得到的错误:(
全部在一行中,“-Sreplyto”中没有空格)
我从以下位置收到此邮件命令:
None of these worked for me (Ubuntu 12.04) but finally with trial & error I got:
(all in one line, there is no space in "-Sreplyto")
I got this mail command from:
大多数人在尝试正确伪造电子邮件上的发件人地址时需要更改两个值。 第一个是起始地址,第二个是起始地址。 在线提供的许多解决方案仅更改这些值之一。
如果作为 root,我尝试一个简单的邮件命令给自己发送一封电子邮件,它可能看起来像这样。
<代码>
回显“测试”| mail -s "a test" [电子邮件受保护]
并且相关日志:
<代码>
2 月 6 日 09:02:51 myserver postfix/qmgr[28875]:B10322269D:from= [电子邮件受保护]>,大小=437,nrcpt=1(队列处于活动状态)
2 月 6 日 09:02:52 myserver postfix/smtp[19848]:B10322269D:to= [电子邮件受保护]>,中继=myMTA[xxxx]:25,延迟=0.34,延迟=0.1/0/0.11/0.13,dsn=2.0.0,状态=已发送(250 Ok 0000014b5f678593-a0e399ef -a801-4655-ad6b-19864a220f38-000000)
尝试使用
-- 更改发件人地址
<代码>
回显“测试”| mail -s "a test" [电子邮件受保护] -- [email protected]
这会更改 orig-to 值,但不会更改 from价值:, orig_to=<[电子邮件受保护]>,中继=myMTA[xxxx]:25,延迟=0.31,延迟=0.06/0/0.09/0.15,dsn=2.0.0,状态=已发送(250 确定 0000014b5f6d48e2-a98b70be-fb02-44e0-8eb3-e4f5b1820265-000000)
<代码>
2 月 6 日 09:09:09 myserver postfix/qmgr[28875]: 6BD362269D: from= [电子邮件受保护]>,大小=474,nrcpt=2(队列处于活动状态)
2 月 6 日 09:09:09 myserver postfix/smtp[20505]: 6BD362269D: to=
接下来
尝试使用 -r 和 -- 来调整 from 和 orig-to 。
<代码>
回显“测试”| mail -s "a test" -r [电子邮件受保护] [电子邮件受保护] -- [电子邮件受保护]
日志:
<代码>
2 月 6 日 09:17:11 myserver postfix/qmgr[28875]:E3B972264C:from= [电子邮件受保护]>,大小=459,nrcpt=2(队列处于活动状态)
2 月 6 日 09:17:11 myserver postfix/smtp[21559]:E3B972264C:to= [电子邮件受保护]>, orig_to=[电子邮件受保护] >,中继=myMTA[xxxx]:25,延迟=1.1,延迟=0.56/0.24/0.11/0.17,dsn=2.0.0,状态=已发送(250 OK 0000014b5f74a2c0-c06709f0-4e8d-4d7e- 9abf-dbcea2bee2ea-000000)
这就是它对我的作用。 希望这对某人有帮助。
Most people need to change two values when trying to correctly forge the from address on an email. First is the from address and the second is the orig-to address. Many of the solutions offered online only change one of these values.
If as root, I try a simple mail command to send myself an email it might look like this.
echo "test" | mail -s "a test" [email protected]
And the associated logs:
Feb 6 09:02:51 myserver postfix/qmgr[28875]: B10322269D: from=<[email protected]>, size=437, nrcpt=1 (queue active)
Feb 6 09:02:52 myserver postfix/smtp[19848]: B10322269D: to=<[email protected]>, 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)
Trying to change the from address with --
echo "test" | mail -s "a test" [email protected] -- [email protected]
This changes the orig-to value but not the from value:
Feb 6 09:09:09 myserver postfix/qmgr[28875]: 6BD362269D: from=<[email protected]>, size=474, nrcpt=2 (queue active)
Feb 6 09:09:09 myserver postfix/smtp[20505]: 6BD362269D: to=<me@noone>, orig_to=<[email protected]>, 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)
Next trying it with a -r and a -- to adjust the from and orig-to.
echo "test" | mail -s "a test" -r [email protected] [email protected] -- [email protected]
And the logs:
Feb 6 09:17:11 myserver postfix/qmgr[28875]: E3B972264C: from=<[email protected]>, size=459, nrcpt=2 (queue active)
Feb 6 09:17:11 myserver postfix/smtp[21559]: E3B972264C: to=<[email protected]>, orig_to=<[email protected]>, 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)
This is how it's working for me. Hope this helps someone.
这是一个解决方案。
-r 之后的第二个最简单的解决方案(即指定 From: 标头并通过换行符将其与正文分开,这样
仅适用于少数邮件版本,不知道 redhat 携带什么版本)。
PS:大多数版本的邮件都很糟糕!
Here's a solution.
The second easiest solution after -r (which is to specify a From: header and separate it from the body by a newline like this
works in only a few mail versions, don't know what version redhat carries).
PS: Most versions of mail suck!
您可以通过首先添加 -- 将 sendmail 选项附加到邮件命令的末尾。 -f 是 sendmail 上用于设置发件人地址的命令。 所以你可以这样做:
mail [email protected] -- -f < a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6a190f040e0f182a080b1844090507">[电子邮件受保护]
You can append sendmail options to the end of the mail command by first adding --. -f is the command on sendmail to set the from address. So you can do this:
mail [email protected] -- -f [email protected]
以上都不适合我。 我花了很长时间才弄清楚,希望这对下一个人有帮助。
我正在使用 Ubuntu 12.04 LTS 和 mailutils v2.1。
我在网上的某个地方找到了这个解决方案,不知道在哪里,无法再次找到它:
使用的完整命令:
None of the above worked for me. And it took me long to figure it out, hopefully this helps the next guy.
I'm using Ubuntu 12.04 LTS with mailutils v2.1.
I found this solutions somewhere on the net, don't know where, can't find it again:
Full Command used:
在 CentOs5 上: -r [电子邮件受保护]
on CentOs5: -r [email protected]
这适用于 Centos7
echo "这是邮件的主体" | mail -s "电子邮件主题" -r [电子邮件受保护] < a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bdcfd8ded4cdd8d3c9e2dcd9d9cfd8cecefdd8c5dcd0cdd1d893ded2d0">[电子邮件受保护]
This works on Centos7
echo "This is the main body of the mail" | mail -s "Subject of the Email" -r [email protected] [email protected]
这是 2018 年关于 Debian 9 的回答。
请注意 echo 的
-e
允许换行符,mailx 的-r
可以显示名称以及外发电子邮件地址:希望这会有所帮助!
Here's an answer from 2018, on Debian 9 stretch.
Note the
-e
for echo to allow newline characters, and-r
for mailx to show a name along with an outgoing email address:Hope this helps!
或者
or
对于 CentOS,这是工作命令:
For CentOS here is the working command :
感谢所有示例提供者,有些适用,有些则不适用。
下面是另一个对我有用的简单示例格式。
Thanks to all example providers, some worked for some not.
Below is another simple example format that worked for me.