使用邮件命令发送电子邮件时指定发件人
http://www.mindspill.org/962似乎有一个解决方案。
本质:
echo "This is the main body of the mail" | mail -s "Subject of the Email" [email protected] -- -f [email protected]
将无法在centos上运行6 – 2014-02-06 10:15:21
邮件-r [email protected] -R [email protected]
-r =从-地址 -R =回复到地址
作者已表示他的邮件版本不支持此标志。但是,如果你有一个版本,这可以很好地工作。
这里是solution。
-r后(第二个最简单的方法是指定一个发件人:头并将其从体内由一个换行符就像只有少数邮件版本此
$mail -s "Subject" [email protected]
From: Joel <[email protected]>
Hi!
.
作品分开,不知道什么版本的红帽进行)。
PS:大多数版本的邮件吸!
您可以先添加附加sendmail的选项,邮件命令结束 - 。 -f是sendmail上设置发件人地址的命令。所以,你可以这样做:
您可以指定任何额外的头,你可能需要使用-a
$mail -s "Some random subject" -a "From: [email protected]" [email protected]
没有这些工作对我来说(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
以上都不为我工作。我花了很长时间才弄明白,希望这有助于下一个人。
我使用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]
echo "This is the main body of the mail" | mail -s "Subject of the Email" [email protected] -- -f [email protected] -F "Elvis Presley"
或
echo "This is the main body of the mail" | mail -s "Subject of the Email" [email protected] -aFrom:"Elvis Presley<[email protected]>"
通过SMTP发送时,mail
手册页建议设置from
变量,以这样的方式
mail -s Subject -S [email protected] [email protected]
否则,使用-r
选项。
测试在CentOS 6
你也可以附上使用下面的语法的文件:mail -s Subject -S [email protected] [email protected] <absolute_path_of_file_to_be_attached>
大多数人需要改变两个值试图正确地伪造的地址上的电子邮件时。首先是从地址,第二是原始地址。网上提供的许多解决方案仅改变其中的一个值。
如果是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)
这是它是如何为我工作。希望这可以帮助某人。
感谢所有示例供应商,有些供应商不是。 下面是另一个简单的示例格式,为我工作。
echo "Sample body" | mail -s "Test email" [email protected] [email protected]
这部作品Centos7
echo "This is the main body of the mail" | mail -s "Subject of the Email" -r [email protected] [email protected]
我面临着同样的问题。但我解决了这个问题,只是在/ect/passwd字段中设置了geko字段。 Postfix默认发送来自用户登录的邮件。让我们假设你想从字段变成警报。你只需要在你喜欢的任何编辑器中编辑/ ect/passwd文件。
- VIM/ECT/passwd中
根:X:0:0:警报:/根:/斌/庆典
- 重新启动后缀。
- echo“这是邮件的主体”| mail -s“电子邮件的主题”[email protected]
现在检查结果。
现在处于收件人状态。 From将显示为Alerts,正如您在geko字段中指定的那样。 希望这个解决方案适合你。
删除'重复'标记。我相信这个标签的用法是不鼓励的。 – 2008-09-23 06:47:36
只需要输入“man mail”,你可能会很快得到这个问题的答案,它会告诉你这个命令的手册。 – 2008-09-23 06:50:51