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条回答
甜甜的少女心
2楼-- · 2020-02-17 04:53

You can specify any extra header you may need with -a

$mail -s "Some random subject" -a "From: some@mail.tld" to@mail.tld
查看更多
smile是对你的礼貌
3楼-- · 2020-02-17 04:53

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.

  1. vim /ect/passwd

root:x:0:0:Alerts:/root:/bin/bash

  1. Restart postfix.

Now check the result.

  1. echo "This is the main body of the mail" | mail -s "Subject of the Email" 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.

查看更多
男人必须洒脱
4楼-- · 2020-02-17 04:54

When sending over SMTP, the mail man page advises to set the from variable, in this way (Tested on CentOS 6):

mail -s Subject -S from=sender@example.com recipient@example.com

You could also attach a file using the -a option:

mail -s Subject -S from=sender@example.com -a path_to_attachement recipient@example.com
查看更多
聊天终结者
5楼-- · 2020-02-17 04:59

mail -r from@from.from -R from@from.com

-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.

查看更多
登录 后发表回答