Linux 使用 mail 命令发送电子邮件时指定发件人用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/119390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Specify the from user when sending email using the mail command
提问by Joel Cunningham
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.
有谁知道如何在使用 mail 命令发送电子邮件时更改 from 用户?我已经浏览了手册页,但看不到如何执行此操作。
We are running Redhat Linux 5.
我们正在运行 Redhat Linux 5。
采纳答案by Paolo Bergantino
http://www.mindspill.org/962seems to have a solution.
http://www.mindspill.org/962似乎有一个解决方案。
Essentially:
本质上:
echo "This is the main body of the mail" | mail -s "Subject of the Email" [email protected] -- -f [email protected]
echo "This is the main body of the mail" | mail -s "Subject of the Email" [email protected] -- -f [email protected]
回答by bfabry
mail -r [email protected] -R [email protected]
邮件 -r [email protected] -R [email protected]
-r = from-addr -R = reply-to addr
-r = from-addr -R = 回复地址
The author has indicated his version of mail doesn't support this flag. But if you have a version that does this works fine.
作者已表示他的邮件版本不支持此标志。但是如果你有一个可以正常工作的版本。
回答by Vinko Vrsalovic
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
-r 之后的第二个最简单的解决方案(即指定 From: 标头并通过这样的换行符将其与正文分开
$mail -s "Subject" [email protected]
From: Joel <[email protected]>
Hi!
.
works in only a few mail versions, don't know what version redhat carries).
仅在几个邮件版本中有效,不知道redhat 带有什么版本)。
PS: Most versions of mail suck!
PS:大多数版本的邮件很烂!
回答by Gerald
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:
您可以通过首先添加 -- 将 sendmail 选项附加到邮件命令的末尾。-f 是 sendmail 上设置发件人地址的命令。所以你可以这样做:
mail [email protected] -- -f [email protected]
邮件收件人@foo.com -- -f [email protected]
回答by daniels
You can specify any extra header you may need with -a
您可以使用 -a 指定您可能需要的任何额外标头
$mail -s "Some random subject" -a "From: [email protected]" [email protected]
回答by fun_vit
on CentOs5: -r [email protected]
在 CentOs5 上:-r [email protected]
回答by Le Droid
None of these worked for me (Ubuntu 12.04) but finally with trial & error I got:
这些都不适合我(Ubuntu 12.04),但最终通过反复试验我得到了:
echo 'my message blabla\nSecond line (optional of course)' |
mail -s "Your message title"
-r 'Your full name<[email protected]>'
-Sreplyto="[email protected]"
[email protected][,[email protected]]
(all in one line, there is no space in "-Sreplyto")
(全部在一行中,“-Sreplyto”中没有空格)
I got this mail command from:
我从以下地址收到此邮件命令:
apt-get install mailutils
回答by Hardus
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.
我将 Ubuntu 12.04 LTS 与 mailutils v2.1 一起使用。
I found this solutions somewhere on the net, don't know where, can't find it again:
我在网上某处找到了这个解决方案,不知道在哪里,又找不到了:
-aFrom:[email protected]
Full Command used:
使用的完整命令:
cat /root/Reports/ServerName-Report-$DATE.txt | mail -s "Server-Name-Report-$DATE" [email protected] -aFrom:[email protected]
回答by Federico Cassinelli
echo "This is the main body of the mail" | mail -s "Subject of the Email" [email protected] -- -f [email protected] -F "Elvis Presley"
or
或者
echo "This is the main body of the mail" | mail -s "Subject of the Email" [email protected] -aFrom:"Elvis Presley<[email protected]>"
回答by G.J
When sending over SMTP, the mail
man page advises to set the from
variable, in this way (Tested on CentOS 6):
通过 SMTP 发送时,mail
手册页建议以from
这种方式设置变量(在 CentOS 6 上测试):
mail -s Subject -S [email protected] [email protected]
You could also attach a file using the -a
option:
您还可以使用以下-a
选项附加文件:
mail -s Subject -S [email protected] -a path_to_attachement [email protected]