Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

Using sendmail from bash script for multiple recipients

I'm running a bash script in cron to send mail to multiple recipients when a certain condition is met.

I've coded the variables like this:

subject="Subject"
from="[email protected]"
recipients="[email protected] [email protected]"
mail="subject:$subject
from:$from
Example Message"

And the actual sending:

echo -e $mail | /usr/sbin/sendmail "$recipients"

The problem is that only [email protected] is receiving the email. How can I change this so all the recipients receive the email?

NOTE: The solution has to be with sendmail, I'm using jailshell and it seems to be the only available method

question from:https://stackoverflow.com/questions/13390894/using-sendmail-from-bash-script-for-multiple-recipients

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try doing this :

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

And another approach, using shell here-doc :

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

Example Message
EOF

Be sure to separate the headers from the body with a blank line as per RFC 822.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...