簡體   English   中英

使用 mail 命令發送電子郵件時指定發件人用戶

[英]Specify the from user when sending email using the mail command

有誰知道如何在使用 mail 命令發送電子郵件時更改 from 用戶? 我已經瀏覽了手冊頁,但看不到如何執行此操作。

我們正在運行 Redhat Linux 5。

您可以使用 -a 指定您可能需要的任何額外標頭

$mail -s "Some random subject" -a "From: some@mail.tld" to@mail.tld

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

本質上:

echo "This is the main body of the mail" | mail -s "Subject of the Email" recipent_address@example.com -- -f from_user@example.com

郵件 -r from@from.from -R from@from.com

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

作者已表示他的郵件版本不支持此標志。 但是如果你有一個可以正常工作的版本。

通過 SMTP 發送時, mail手冊頁建議以這種方式設置from變量(在 CentOS 6 上測試):

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

您還可以使用-a選項附加文件:

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

這些都不適合我(Ubuntu 12.04),但最終通過反復試驗我得到了:

echo 'my message blabla\nSecond line (optional of course)' | 
mail -s "Your message title"
-r 'Your full name<yourSenderAdress@yourDomain.abc>'
-Sreplyto="yourReplyAdressIfDifferent@domain.abc"
destinatorEmail@destDomain.abc[,otherDestinator@otherDomain.abc]

(全部在一行中,“-Sreplyto”中沒有空格)

我從以下地址收到此郵件命令:

apt-get install mailutils

您可以通過首先添加 -- 將 sendmail 選項附加到郵件命令的末尾。 -f 是 sendmail 上設置發件人地址的命令。 所以你可以這樣做:

郵件收件人@foo.com -- -f sender@bar.com

以上都不適合我。 我花了很長時間才弄明白,希望這能幫助下一個人。

我將 Ubuntu 12.04 LTS 與 mailutils v2.1 一起使用。

我在網上某處找到了這個解決方案,不知道在哪里,又找不到了:

-aFrom:Servername-Server@mydomain.com

使用的完整命令:

cat /root/Reports/ServerName-Report-$DATE.txt | mail -s "Server-Name-Report-$DATE" myemailadress@mydomain.com -aFrom:Servername-Server@mydomain.com

這是一個解決方案

-r 之后的第二個最簡單的解決方案(即指定 From: 標頭並通過這樣的換行符將其與正文分開

 $mail -s "Subject" destination@example.com
 From: Joel <joel@example.com>

 Hi!
 .

僅在幾個郵件版本中有效,不知道redhat 帶有什么版本)。

PS:大多數版本的郵件很爛!

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"

要么

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

大多數人在嘗試正確偽造電子郵件上的發件人地址時需要更改兩個值。 第一個是起始地址,第二個是起始地址。 許多在線提供的解決方案僅更改其中一個值。

如果作為 root,我嘗試一個簡單的郵件命令給自己發送一封電子郵件,它可能看起來像這樣。 echo "test" | mail -s "a test" me@noone.com

以及相關的日志: Feb 6 09:02:51 myserver postfix/qmgr[28875]: B10322269D: from=<root@myserver.com>, size=437, nrcpt=1 (queue active) Feb 6 09:02:52 myserver postfix/smtp[19848]: B10322269D: to=<me@noone.com>, relay=myMTA[xxxx]: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" me@noone.com -- dude@thisguy.com更改發件人地址echo "test" | mail -s "a test" me@noone.com -- dude@thisguy.com

這會更改 orig-to 值而不是 from 值: Feb 6 09:09:09 myserver postfix/qmgr[28875]: 6BD362269D: from=<root@myserver.com>, size=474, nrcpt=2 (queue active) Feb 6 09:09:09 myserver postfix/smtp[20505]: 6BD362269D: to=<me@noone>, orig_to=<dude@thisguy.com>, relay=myMTA[xxxx]: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 和 a -- 來調整 from 和 orig-to。 echo "test" | mail -s "a test" -r dude@comeguy.com me@noone.com -- dude@someguy.com

和日志: Feb 6 09:17:11 myserver postfix/qmgr[28875]: E3B972264C: from=<dude@someguy.com>, size=459, nrcpt=2 (queue active) Feb 6 09:17:11 myserver postfix/smtp[21559]: E3B972264C: to=<me@noone.com>, orig_to=<dude@someguy.com>, relay=myMTA[xxxx]: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)

這就是它對我的工作方式。 希望這可以幫助某人。

這適用於 Centos7

echo "This is the main body of the mail" | mail -s "Subject of the Email" -r seneder_address@whatever.com recipent_address@example.com

這是 2018 年在 Debian 9 上的答案。

請注意-e用於 echo 以允許換行符, -r用於 mailx 以顯示名稱以及外發電子郵件地址:

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

希望這可以幫助!

對於 CentOS,這里是工作命令:

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

在 CentOs5 上:-r from@me.omg

感謝所有示例提供者,有些人對有些人無效。 下面是另一種對我有用的簡單示例格式。

echo "Sample body" | mail -s "Test email" from=sender-addrs@example.com recepient-addres@example.com

我遇到了同樣的問題。 但我解決了這個問題,只是在/ect/passwd字段中設置了 geko 字段。 Postfix 默認從用戶登錄發送郵件。 假設您想從字段更改為警報。 您只需要在您喜歡的任何編輯器中編輯 /ect/passwd 文件。

  1. vim /ect/passwd

root:x:0:0:警報:/root:/bin/bash

  1. 重新啟動后綴。

現在檢查結果。

  1. echo "這是郵件的主體" | mail -s "郵件主題" user@domain.com

現在在收件人。 從將顯示為警告,你在GEKO領域已經確定。 希望這個解決方案對你有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM