シェルスクリプトを使用して電子メールを送信する

シェルスクリプトを使用して電子メールを送信する

シェルスクリプトを実行すると、指定されたすべての電子メールにメッセージが送信されるように、単一の変数に複数の電子メールを追加できますか?

ベストアンサー1

スクリプトでsendmailまたはを使用していると仮定するとmail(どちらもコンマで区切られた文字列が受信者リストに必要です)、IDを関連付けることができます(または次のようにリストとして直接作成できます)。

$: recipients="[email protected], [email protected], [email protected]"

または接続:

$: base_recipients="[email protected], [email protected]"
$: full_recipients="$base_recipients, [email protected]"

$: echo $full_recipients
[email protected], [email protected], [email protected]  

sendmail以下は、3つの異なるメールIDを使用してメールを送信する例です。

#!/bin/bash

recipients="[email protected], [email protected], [email protected]"
subject="Mail to you all"
from="[email protected]"

message_txt="Hi all!\n This is a message to all 3 of you!.\n cheers, Me."

/usr/sbin/sendmail "$recipients" << EOF
subject:$subject
from:$from
$message_txt
EOF

おすすめ記事