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.
我们正在运行Redhat Linux 5。
15 个解决方案
#1
26
http://www.mindspill.org/962 seems 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" recipent_address@example.com -- -f from_user@example.com
echo "这是邮件" |邮件-s "的主体,邮件" recipent_address@example.com -- f from_user@example.com "
#2
59
You can specify any extra header you may need with -a
您可以使用-a指定您可能需要的任何附加头
$mail -s "Some random subject" -a "From: some@mail.tld" to@mail.tld
#3
20
mail -r from@from.from -R from@from.com
邮件-r from@from.com/
-r = from-addr -R = reply-to addr
-r = from-addr -r =回复-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.
作者表示他的邮件版本不支持这个标志。但是如果你有一个版本可以做到这一点。
#4
12
When sending over SMTP, the mail
man page advises to set the from
variable, in this way:
在发送SMTP时,mail man页面建议将from变量设置为:
mail -s Subject -S from=sender@example.com recipient@example.com
Otherwise, use the -r
option.
否则,使用-r选项。
Tested on CentOS 6.
测试在CentOS 6。
You could also attach a file using the below syntax :mail -s Subject -S from=sender@example.com recipient@example.com <absolute_path_of_file_to_be_attached>
您还可以使用以下语法附加一个文件:mail -s Subject -s from=sender@example.com收信人@example.com
#5
5
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<yourSenderAdress@yourDomain.abc>'
-Sreplyto="yourReplyAdressIfDifferent@domain.abc"
destinatorEmail@destDomain.abc[,otherDestinator@otherDomain.abc]
(all in one line, there is no space in "-Sreplyto")
(在一行中,“-Sreplyto”没有空格)
I got this mail command from:
我收到这个邮件命令:
apt-get install mailutils
#6
3
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选项附加到mail命令的末尾。-f是sendmail上设置from地址的命令。你可以这样做:
mail recipient@foo.com -- -f sender@bar.com
邮箱收件人@foo.com -- -f sender@bar.com。
#7
2
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: header并通过如下的换行将其从主体中分离出来
$mail -s "Subject" destination@example.com
From: Joel <joel@example.com>
Hi!
.
works in only a few mail versions, don't know what version redhat carries).
只适用于几个邮件版本,不知道redhat携带的是什么版本)。
PS: Most versions of mail suck!
大多数版本的邮件都很糟糕!
#8
2
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:Servername-Server@mydomain.com
Full Command used:
完整的命令使用:
cat /root/Reports/ServerName-Report-$DATE.txt | mail -s "Server-Name-Report-$DATE" myemailadress@mydomain.com -aFrom:Servername-Server@mydomain.com
#9
1
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.
大多数人在尝试正确伪造电子邮件上的from地址时需要改变两个值。第一个是from地址,第二个是origto地址。许多在线提供的解决方案只改变了其中的一个价值。
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" me@noone.com
如果作为root用户,我尝试使用一个简单的邮件命令给自己发一封邮件,它可能是这样的。echo "test" | mail -s "a test" me@noone.com
And the associated logs: 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)
与相关日志:2月6日09:02:02 02:51 mypostfix /qmgr[28875]: B10322269D: from=
Trying to change the from address with -- echo "test" | mail -s "a test" me@noone.com -- dude@thisguy.com
尝试用- echo "test" | mail -s "a test" me@noone.com - dude@thisguy.com更改from地址
This changes the orig-to value but not the from value: 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)
这改变了origto值,但不改变from值:2月6日09:09 myserver postfix/qmgr[28875]: 6BD362269D: from=
Next trying it with a -r and a -- to adjust the from and orig-to. echo "test" | mail -s "a test" -r dude@comeguy.com me@noone.com -- dude@someguy.com
接下来用-r和- a来调整from和origto。echo "test" | mail -s "a test" -r dude@comguy.com me@noone.com - dude@someguy.com
And the logs: 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)
与日志:2月6日09:17 - 11服务器postfix/qmgr[28875]: E3B972264C: from=
This is how it's working for me. Hope this helps someone.
这就是我的工作方式。希望这可以帮助别人。
#10
1
This works on Centos7
这适用于Centos7
echo "This is the main body of the mail" | mail -s "Subject of the Email" -r seneder_address@whatever.com recipent_address@example.com
echo "这是邮件的主体" |邮件-s "邮件主题" -r seneder_address@whatever.com recipentpent_address@example.com
#11
0
on CentOs5: -r from@me.omg
CentOs5:- r from@me.omg
#12
0
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"
or
或
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>"
#13
0
Thanks to all example providers, some worked for some not. Below is another simple example format that worked for me.
多亏了所有的示例提供者,有些起作用了,有些则不起作用。下面是另一个简单的示例格式。
echo "Sample body" | mail -s "Test email" from=sender-addrs@example.com recepient-addres@example.com
#14
0
Here's an answer from 2018, on Debian 9 stretch.
这是2018年的答案,在Debian 9号展区。
Note the -e
for echo to allow newline characters, and -r
for mailx to show a name along with an outgoing email address:
注意-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
Hope this helps!
希望这可以帮助!
#15
-1
I faced the same issue. But i solved the problem just be setting geko field in /ect/passwd field. Postfix by default send the mail from user login. Lets suppose you want to change from field to Alert. You just need to edit /ect/passwd file in any editor you like.
我面临着同样的问题。但是我解决了在/ect/passwd字段中设置geko字段的问题。默认情况下,从用户登录发送邮件。假设您希望从字段更改为Alert。您只需要在任何您喜欢的编辑器中编辑/ect/passwd文件。
- vim /ect/passwd
- vim / ect / passwd
root:x:0:0:Alerts:/root:/bin/bash
根:x:0时:警告:/根:/ bin / bash
- Restart postfix.
- 重启后缀。
Now check the result.
现在检查结果。
- echo "This is the main body of the mail" | mail -s "Subject of the Email" user@domain.com
- echo“这是邮件的主体”|邮件-s“邮件主题”user@domain.com。
Now in recipient. From will be shown as Alerts as you have specified in geko field. Hope this solution works for you.
现在在接收方。从将显示为警报,正如您在geko字段中指定的那样。希望这个解决方案对你有效。
#1
26
http://www.mindspill.org/962 seems 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" recipent_address@example.com -- -f from_user@example.com
echo "这是邮件" |邮件-s "的主体,邮件" recipent_address@example.com -- f from_user@example.com "
#2
59
You can specify any extra header you may need with -a
您可以使用-a指定您可能需要的任何附加头
$mail -s "Some random subject" -a "From: some@mail.tld" to@mail.tld
#3
20
mail -r from@from.from -R from@from.com
邮件-r from@from.com/
-r = from-addr -R = reply-to addr
-r = from-addr -r =回复-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.
作者表示他的邮件版本不支持这个标志。但是如果你有一个版本可以做到这一点。
#4
12
When sending over SMTP, the mail
man page advises to set the from
variable, in this way:
在发送SMTP时,mail man页面建议将from变量设置为:
mail -s Subject -S from=sender@example.com recipient@example.com
Otherwise, use the -r
option.
否则,使用-r选项。
Tested on CentOS 6.
测试在CentOS 6。
You could also attach a file using the below syntax :mail -s Subject -S from=sender@example.com recipient@example.com <absolute_path_of_file_to_be_attached>
您还可以使用以下语法附加一个文件:mail -s Subject -s from=sender@example.com收信人@example.com
#5
5
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<yourSenderAdress@yourDomain.abc>'
-Sreplyto="yourReplyAdressIfDifferent@domain.abc"
destinatorEmail@destDomain.abc[,otherDestinator@otherDomain.abc]
(all in one line, there is no space in "-Sreplyto")
(在一行中,“-Sreplyto”没有空格)
I got this mail command from:
我收到这个邮件命令:
apt-get install mailutils
#6
3
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选项附加到mail命令的末尾。-f是sendmail上设置from地址的命令。你可以这样做:
mail recipient@foo.com -- -f sender@bar.com
邮箱收件人@foo.com -- -f sender@bar.com。
#7
2
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: header并通过如下的换行将其从主体中分离出来
$mail -s "Subject" destination@example.com
From: Joel <joel@example.com>
Hi!
.
works in only a few mail versions, don't know what version redhat carries).
只适用于几个邮件版本,不知道redhat携带的是什么版本)。
PS: Most versions of mail suck!
大多数版本的邮件都很糟糕!
#8
2
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:Servername-Server@mydomain.com
Full Command used:
完整的命令使用:
cat /root/Reports/ServerName-Report-$DATE.txt | mail -s "Server-Name-Report-$DATE" myemailadress@mydomain.com -aFrom:Servername-Server@mydomain.com
#9
1
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.
大多数人在尝试正确伪造电子邮件上的from地址时需要改变两个值。第一个是from地址,第二个是origto地址。许多在线提供的解决方案只改变了其中的一个价值。
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" me@noone.com
如果作为root用户,我尝试使用一个简单的邮件命令给自己发一封邮件,它可能是这样的。echo "test" | mail -s "a test" me@noone.com
And the associated logs: 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)
与相关日志:2月6日09:02:02 02:51 mypostfix /qmgr[28875]: B10322269D: from=
Trying to change the from address with -- echo "test" | mail -s "a test" me@noone.com -- dude@thisguy.com
尝试用- echo "test" | mail -s "a test" me@noone.com - dude@thisguy.com更改from地址
This changes the orig-to value but not the from value: 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)
这改变了origto值,但不改变from值:2月6日09:09 myserver postfix/qmgr[28875]: 6BD362269D: from=
Next trying it with a -r and a -- to adjust the from and orig-to. echo "test" | mail -s "a test" -r dude@comeguy.com me@noone.com -- dude@someguy.com
接下来用-r和- a来调整from和origto。echo "test" | mail -s "a test" -r dude@comguy.com me@noone.com - dude@someguy.com
And the logs: 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)
与日志:2月6日09:17 - 11服务器postfix/qmgr[28875]: E3B972264C: from=
This is how it's working for me. Hope this helps someone.
这就是我的工作方式。希望这可以帮助别人。
#10
1
This works on Centos7
这适用于Centos7
echo "This is the main body of the mail" | mail -s "Subject of the Email" -r seneder_address@whatever.com recipent_address@example.com
echo "这是邮件的主体" |邮件-s "邮件主题" -r seneder_address@whatever.com recipentpent_address@example.com
#11
0
on CentOs5: -r from@me.omg
CentOs5:- r from@me.omg
#12
0
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"
or
或
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>"
#13
0
Thanks to all example providers, some worked for some not. Below is another simple example format that worked for me.
多亏了所有的示例提供者,有些起作用了,有些则不起作用。下面是另一个简单的示例格式。
echo "Sample body" | mail -s "Test email" from=sender-addrs@example.com recepient-addres@example.com
#14
0
Here's an answer from 2018, on Debian 9 stretch.
这是2018年的答案,在Debian 9号展区。
Note the -e
for echo to allow newline characters, and -r
for mailx to show a name along with an outgoing email address:
注意-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
Hope this helps!
希望这可以帮助!
#15
-1
I faced the same issue. But i solved the problem just be setting geko field in /ect/passwd field. Postfix by default send the mail from user login. Lets suppose you want to change from field to Alert. You just need to edit /ect/passwd file in any editor you like.
我面临着同样的问题。但是我解决了在/ect/passwd字段中设置geko字段的问题。默认情况下,从用户登录发送邮件。假设您希望从字段更改为Alert。您只需要在任何您喜欢的编辑器中编辑/ect/passwd文件。
- vim /ect/passwd
- vim / ect / passwd
root:x:0:0:Alerts:/root:/bin/bash
根:x:0时:警告:/根:/ bin / bash
- Restart postfix.
- 重启后缀。
Now check the result.
现在检查结果。
- echo "This is the main body of the mail" | mail -s "Subject of the Email" user@domain.com
- echo“这是邮件的主体”|邮件-s“邮件主题”user@domain.com。
Now in recipient. From will be shown as Alerts as you have specified in geko field. Hope this solution works for you.
现在在接收方。从将显示为警报,正如您在geko字段中指定的那样。希望这个解决方案对你有效。