65

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

RedhatLinux5を実行しています。

4

16 に答える 16

78

-aを使用して、必要になる可能性のある追加のヘッダーを指定できます。

$mail -s "Some random subject" -a "From: some@mail.tld" to@mail.tld
于 2008-09-23T07:03:54.037 に答える
27

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

于 2008-09-23T06:44:28.653 に答える
25

メール -r from@from.from -R from@from.com

-r = from-addr -R = 返信先アドレス

著者は、彼のバージョンのメールがこのフラグをサポートしていないことを示しています。ただし、これを行うバージョンがあれば、これは正常に機能します。

于 2008-09-23T06:31:51.073 に答える
21

SMTP 経由で送信する場合、mailman ページでは次のように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
于 2014-05-05T12:11:34.497 に答える
7

これらのどれも私にとってはうまくいきませんでした(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
于 2013-10-04T20:58:45.470 に答える
5

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

メールrecipient@foo.com---fsender@bar.com

于 2008-09-23T06:49:34.773 に答える
2

ここに解決策があります。

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

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

 Hi!
 .

いくつかのメール バージョンでのみ動作します。redhat のバージョンは不明です)。

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

于 2008-09-23T06:34:08.523 に答える
1

これは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

于 2016-05-13T00:40:18.083 に答える
1

CentOs5 の場合: -r from@me.omg

于 2010-02-03T11:01:30.087 に答える
1
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>"
于 2014-04-15T21:42:08.877 に答える
0

すべての例のプロバイダーのおかげで、いくつかはうまくいきませんでした。以下は、私にとってうまくいった別の簡単なフォーマットの例です。

echo "Sample body" | mail -s "Test email" from=sender-addrs@example.com recepient-addres@example.com
于 2015-09-21T18:36:54.120 に答える
-1

私は同じ問題に直面しました。しかし、 /ect/passwdフィールドにgekoフィールドを設定するだけで問題を解決しました。デフォルトでは、Postfix はユーザー ログインからメールを送信します。フィールドからアラートに変更したいとします。好きなエディタで /ect/passwd ファイルを編集するだけです。

  1. vim /ect/passwd

root:x:0:0:アラート:/root:/bin/bash

  1. postfix を再起動します。

今すぐ結果を確認してください。

  1. echo "メールの本文です" | mail -s "メールの件名" user@domain.com

今受信者に。差出人は、geko フィールドで指定したアラートとして表示されます。この解決策がうまくいくことを願っています。

于 2016-08-22T23:08:37.053 に答える