2008-09-23 177 views
46

有谁知道如何使用邮件命令发送邮件时更改发件人吗?我浏览了手册页,看不到如何做到这一点。使用邮件命令发送电子邮件时指定发件人

我们正在运行红帽Linux 5

+0

删除'重复'标记。我相信这个标签的用法是不鼓励的。 – 2008-09-23 06:47:36

+4

只需要输入“man mail”,你可能会很快得到这个问题的答案,它会告诉你这个命令的手册。 – 2008-09-23 06:50:51

回答

19

邮件-r [email protected] -R [email protected]

-r =从-地址 -R =回复到地址

作者已表示他的邮件版本不支持此标志。但是,如果你有一个版本,这可以很好地工作。

+0

对于我们拥有的邮件版本,-r不是邮件命令选项的有效选项。 – 2008-09-23 06:35:53

+1

在Debian Wheezy上,-r正在使用邮件命令编辑From地址,但-R不能编辑ReplyTo地址。 – baptx 2015-02-22 19:39:27

+1

只是为了澄清其他人-r是否影响哪些地址检查spf记录 – Kevin 2015-03-16 18:38:49

2

这里是solution

-r后(第二个最简单的方法是指定一个发件人:头并将其从体内由一个换行符就像只有少数邮件版本此

$mail -s "Subject" [email protected] 
From: Joel <[email protected]> 

Hi! 
. 

作品分开,不知道什么版本的红帽进行)。

PS:大多数版本的邮件吸!

5

没有这些工作对我来说(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]] 

(全部在一行中,存在“-Sreplyto”无空格)

从我得到这个邮件命令:

apt-get install mailutils 
1

以上都不为我工作。我花了很长时间才弄明白,希望这有助于下一个人。

我使用Ubuntu 12.04 LTS和mailutils v2.1。

我发现这个解决方案的地方上了网,不知道在哪里,无法再次找到它:

-aFrom:[email protected] 

全部使用的命令:

cat /root/Reports/ServerName-Report-$DATE.txt | mail -s "Server-Name-Report-$DATE" [email protected] -aFrom:[email protected] 
1

大多数人需要改变两个值试图正确地伪造的地址上的电子邮件时。首先是从地址,第二是原始地址。网上提供的许多解决方案仅改变其中的一个值。

如果是root用户,我尝试一个简单的邮件命令发送自己的电子邮件,它可能看起来像这样。 echo "test" | mail -s "a test" [email protected]

和相关的日志: 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)

试图从地址与改变 - echo "test" | mail -s "a test" [email protected] -- [email protected]

这改变了原稿值增加,但不是从价值: 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=<[email protected]>, 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)

接下来用-r和 - 来调整from和orig-to。 echo "test" | mail -s "a test" -r [email protected] [email protected] -- [email protected]

,并将日志: 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)

这是它是如何为我工作。希望这可以帮助某人。

-1

我面临着同样的问题。但我解决了这个问题,只是在/ect/passwd字段中设置了geko字段。 Postfix默认发送来自用户登录的邮件。让我们假设你想从字段变成警报。你只需要在你喜欢的任何编辑器中编辑/ ect/passwd文件。

  1. VIM/ECT/passwd中

根:X:0:0:警报:/根:/斌/庆典

  • 重新启动后缀。
  • 现在检查结果。

    1. echo“这是邮件的主体”| mail -s“电子邮件的主题”[email protected]

    现在处于收件人状态。 From将显示为Alerts,正如您在geko字段中指定的那样。 希望这个解决方案适合你。