Specify the from user when sending email using the

2020-02-17 04:15发布

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.

16条回答
▲ chillily
2楼-- · 2020-02-17 04:38

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
查看更多
我命由我不由天
3楼-- · 2020-02-17 04:41

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 recipient@foo.com -- -f sender@bar.com

查看更多
我只想做你的唯一
4楼-- · 2020-02-17 04:41

For CentOS here is the working command :

mail -s Subject -S from=sender@example.com recipient@example.com
查看更多
The star\"
5楼-- · 2020-02-17 04:42

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:

-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
查看更多
对你真心纯属浪费
6楼-- · 2020-02-17 04:47

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" recipent_address@example.com -- -f from_user@example.com

查看更多
仙女界的扛把子
7楼-- · 2020-02-17 04:52
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>"
查看更多
登录 后发表回答