mailコマンドを使用して電子メールを送信するときにfromユーザーを変更する方法を知っている人はいますか?マニュアルページを調べましたが、これを行う方法がわかりません。
RedhatLinux5を実行しています。
-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
man ページでは次のように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
最初に-を追加することで、mailコマンドの最後にsendmailオプションを追加できます。-fは、差出人アドレスを設定するためのsendmailのコマンドです。だからあなたはこれを行うことができます:
メールrecipient@foo.com---fsender@bar.com
ここに解決策があります。
-r に続く 2 番目に簡単な解決策 (From: ヘッダーを指定し、次のように改行で本文から分離することです)
$mail -s "Subject" destination@example.com
From: Joel <joel@example.com>
Hi!
.
いくつかのメール バージョンでのみ動作します。redhat のバージョンは不明です)。
PS: ほとんどのバージョンのメールは最悪です!
これは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
CentOs5 の場合: -r from@me.omg
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>"
すべての例のプロバイダーのおかげで、いくつかはうまくいきませんでした。以下は、私にとってうまくいった別の簡単なフォーマットの例です。
echo "Sample body" | mail -s "Test email" from=sender-addrs@example.com recepient-addres@example.com
私は同じ問題に直面しました。しかし、 /ect/passwdフィールドにgekoフィールドを設定するだけで問題を解決しました。デフォルトでは、Postfix はユーザー ログインからメールを送信します。フィールドからアラートに変更したいとします。好きなエディタで /ect/passwd ファイルを編集するだけです。
root:x:0:0:アラート:/root:/bin/bash
今すぐ結果を確認してください。
今受信者に。差出人は、geko フィールドで指定したアラートとして表示されます。この解決策がうまくいくことを願っています。