使用mail命令发送邮件时指定发件人用户

发布于 2024-07-05 13:04:36 字数 94 浏览 7 评论 0原文

有谁知道使用 mail 命令发送电子邮件时如何更改发件人用户? 我浏览了手册页,但不知道如何执行此操作。

我们正在运行 Redhat Linux 5。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

九公里浅绿 2024-07-12 13:04:36

mail -r [电子邮件受保护] -R [电子邮件受保护]

-r = from-addr
-R = 回复地址

作者已表明他的邮件版本不支持此标志。 但如果你有一个版本可以正常工作。

mail -r [email protected] -R [email protected]

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

找回味觉 2024-07-12 13:04:36

您可以使用 -a 指定您可能需要的任何额外标头

$mail -s "Some random subject" -a "From: [email protected]" [email protected]

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

$mail -s "Some random subject" -a "From: [email protected]" [email protected]
别把无礼当个性 2024-07-12 13:04:36

http://www.mindspill.org/962 似乎有一个解决方案。

本质上:

echo“这是邮件的主体”| mail -s "电子邮件主题" [电子邮件受保护] -- - f [电子邮件受保护]

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" [email protected] -- -f [email protected]

明媚殇 2024-07-12 13:04:36

通过 SMTP 发送时,mail 手册页建议设置 from 变量,这样(在 CentOS 6 上测试):

mail -s Subject -S [email protected] [email protected]

您还可以使用 附加文件>-a 选项:

mail -s Subject -S [email protected] -a path_to_attachement [email protected]

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 [email protected] [email protected]

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

mail -s Subject -S [email protected] -a path_to_attachement [email protected]
谁对谁错谁最难过 2024-07-12 13:04:36

这些都不适合我(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

None of these worked for me (Ubuntu 12.04) but finally with trial & error I got:

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

(all in one line, there is no space in "-Sreplyto")

I got this mail command from:

apt-get install mailutils
莫相离 2024-07-12 13:04:36

大多数人在尝试正确伪造电子邮件上的发件人地址时需要更改两个值。 第一个是起始地址,第二个是起始地址。 在线提供的许多解决方案仅更改这些值之一。

如果作为 root,我尝试一个简单的邮件命令给自己发送一封电子邮件,它可能看起来像这样。
<代码>
回显“测试”| mail -s "a test" [电子邮件受保护]

并且相关日志:
<代码>
2 月 6 日 09:02:51 myserver postfix/qmgr[28875]:B10322269D:from= [电子邮件受保护]>,大小=437,nrcpt=1(队列处于活动状态)
2 月 6 日 09:02:52 myserver postfix/smtp[19848]:B10322269D:to= [电子邮件受保护]>,中继=myMTA[xxxx]:25,延迟=0.34,延迟=0.1/0/0.11/0.13,dsn=2.0.0,状态=已发送(250 Ok 0000014b5f678593-a0e399ef -a801-4655-ad6b-19864a220f38-000000)
尝试使用

-- 更改发件人地址
<代码>
回显“测试”| mail -s "a test" [电子邮件受保护] -- [email protected]

这会更改 orig-to 值,但不会更改 from价值:
<代码>
2 月 6 日 09:09:09 myserver postfix/qmgr[28875]: 6BD362269D: from= [电子邮件受保护]>,大小=474,nrcpt=2(队列处于活动状态)
2 月 6 日 09:09:09 myserver postfix/smtp[20505]: 6BD362269D: to=, orig_to=<[电子邮件受保护]>,中继=myMTA[xxxx]:25,延迟=0.31,延迟=0.06/0/0.09/0.15,dsn=2.0.0,状态=已发送(250 确定 0000014b5f6d48e2-a98b70be-fb02-44e0-8eb3-e4f5b1820265-000000)
接下来

尝试使用 -r 和 -- 来调整 from 和 orig-to 。
<代码>
回显“测试”| mail -s "a test" -r [电子邮件受保护] [电子邮件受保护] -- [电子邮件受保护]

日志:
<代码>
2 月 6 日 09:17:11 myserver postfix/qmgr[28875]:E3B972264C:from= [电子邮件受保护]>,大小=459,nrcpt=2(队列处于活动状态)
2 月 6 日 09:17:11 myserver postfix/smtp[21559]:E3B972264C:to= [电子邮件受保护]>, orig_to=[电子邮件受保护] >,中继=myMTA[xxxx]:25,延迟=1.1,延迟=0.56/0.24/0.11/0.17,dsn=2.0.0,状态=已发送(250 OK 0000014b5f74a2c0-c06709f0-4e8d-4d7e- 9abf-dbcea2bee2ea-000000)

这就是它对我的作用。 希望这对某人有帮助。

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.

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" [email protected]

And the associated logs:

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)

Trying to change the from address with --

echo "test" | mail -s "a test" [email protected] -- [email protected]

This changes the orig-to value but not the from value:

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=<me@noone>, 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)

Next trying it with a -r and a -- to adjust the from and orig-to.

echo "test" | mail -s "a test" -r [email protected] [email protected] -- [email protected]

And the logs:

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)

This is how it's working for me. Hope this helps someone.

〃温暖了心ぐ 2024-07-12 13:04:36

这是一个解决方案

-r 之后的第二个最简单的解决方案(即指定 From: 标头并通过换行符将其与正文分开,这样

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

 Hi!
 .

仅适用于少数邮件版本,不知道 redhat 携带什么版本)。

PS:大多数版本的邮件都很糟糕!

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

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

 Hi!
 .

works in only a few mail versions, don't know what version redhat carries).

PS: Most versions of mail suck!

莳間冲淡了誓言ζ 2024-07-12 13:04:36

您可以通过首先添加 -- 将 sendmail 选项附加到邮件命令的末尾。 -f 是 sendmail 上用于设置发件人地址的命令。 所以你可以这样做:

mail [email protected] -- -f < a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6a190f040e0f182a080b1844090507">[电子邮件受保护]

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 [email protected] -- -f [email protected]

起风了 2024-07-12 13:04:36

以上都不适合我。 我花了很长时间才弄清楚,希望这对下一个人有帮助。

我正在使用 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]

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:[email protected]

Full Command used:

cat /root/Reports/ServerName-Report-$DATE.txt | mail -s "Server-Name-Report-$DATE" [email protected] -aFrom:[email protected]
痴骨ら 2024-07-12 13:04:36

这适用于 Centos7

echo "这是邮件的主体" | mail -s "电子邮件主题" -r [电子邮件受保护] < a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bdcfd8ded4cdd8d3c9e2dcd9d9cfd8cecefdd8c5dcd0cdd1d893ded2d0">[电子邮件受保护]

This works on Centos7

echo "This is the main body of the mail" | mail -s "Subject of the Email" -r [email protected] [email protected]

Spring初心 2024-07-12 13:04:36

这是 2018 年关于 Debian 9 的回答。

请注意 echo 的 -e 允许换行符,mailx 的 -r 可以显示名称以及外发电子邮件地址:

$ echo -e "testing email via yourisp.com from command line\n\nsent on: $(date)" | mailx -r "Foghorn Leghorn <[email protected]>" -s "test cli email $(date)" -- [email protected]

希望这会有所帮助!

Here's an answer from 2018, on Debian 9 stretch.

Note the -e for echo to allow newline characters, and -r for mailx to show a name along with an outgoing email address:

$ echo -e "testing email via yourisp.com from command line\n\nsent on: $(date)" | mailx -r "Foghorn Leghorn <[email protected]>" -s "test cli email $(date)" -- [email protected]

Hope this helps!

绝不放开 2024-07-12 13:04:36
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]>"
echo "This is the main body of the mail" | mail -s "Subject of the Email" [email protected] -- -f [email protected] -F "Elvis Presley"

or

echo "This is the main body of the mail" | mail -s "Subject of the Email" [email protected] -aFrom:"Elvis Presley<[email protected]>"
权谋诡计 2024-07-12 13:04:36

对于 CentOS,这是工作命令:

mail -s Subject -S [email protected] [email protected]

For CentOS here is the working command :

mail -s Subject -S [email protected] [email protected]
坚持沉默 2024-07-12 13:04:36

感谢所有示例提供者,有些适用,有些则不适用。
下面是另一个对我有用的简单示例格式。

echo "Sample body" | mail -s "Test email" [email protected] [email protected]

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" [email protected] [email protected]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文