web-dev-qa-db-ja.com

mailコマンドを使用して電子メールを送信するときにfromユーザーを指定します

Mailコマンドを使用して電子メールを送信するときに、fromユーザーを変更する方法を知っていますか?私はマニュアルページを調べましたが、これを行う方法がわかりません。

Redhat Linux 5を実行しています。

54
Joel Cunningham

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]

28

-aで必要な追加ヘッダーを指定できます

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

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

-r = from-addr -R = reply-to addr

作成者は、メールのバージョンがこのフラグをサポートしていないことを示しています。ただし、これを行うバージョンがある場合は正常に動作します。

21
bfabry

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]
18
G.J

これらのどれも私にとってはうまくいきませんでした(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]]

(すべて1行で、「-Sreplyto」にはスペースがありません)

私はこのメールコマンドを次から入手しました:

apt-get install mailutils
5
Le Droid

最初に-を追加することにより、sendmailオプションをmailコマンドの最後に追加できます。 -fは、差出人アドレスを設定するsendmailのコマンドです。だからあなたはこれを行うことができます:

mail [email protected] [email protected]

3
Gerald

上記のどれも私にとってはうまくいきませんでした。そして、それを理解するのに時間がかかりました。うまくいけば、これが次の人の助けになります。

Mailutils v2.1でUbuntu 12.04 LTSを使用しています。

私はこの解決策をネットのどこかに見つけましたが、どこにあるのか分からず、再び見つけることができません:

-aFrom:[email protected]

使用される完全なコマンド:

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

ソリューション です。

-rの後の2番目に簡単な解決策(From:ヘッダーを指定し、このような改行で本文から分離することです)

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

 Hi!
 .

いくつかのメールバージョンでのみ動作し、redhatがどのバージョンを搭載しているかはわかりません)。

PS:メールのほとんどのバージョンはダメです!

2
Vinko Vrsalovic
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]>"
1

電子メールの差出人アドレスを正しく偽造しようとすると、ほとんどの人は2つの値を変更する必要があります。最初は送信元アドレスで、2番目は送信元アドレスです。オンラインで提供されるソリューションの多くは、これらの値の1つのみを変更します。

ルートとして、単純なメールコマンドを試して自分にメールを送信すると、次のようになります。 _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=<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)

次に、-rおよびaを使用して、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
Jerad

これはCentos7で動作します

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

1
Santiago Trias

Debian 9ストレッチに関する2018年の回答を以下に示します。

改行文字を許可するエコーの-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]

お役に立てれば!

1
woohoo

centOs5の場合:-r [email protected]

0
fun_vit

CentOSの場合、動作するコマンドは次のとおりです。

mail -s Subject -S [email protected] [email protected]
0
Youssef ASEBRIY

すべてのサンプルプロバイダーのおかげで、一部のプロバイダーは一部のプロバイダーでは機能しませんでした。以下は、私のために働いた別の簡単な例のフォーマットです。

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