从多个收件人bash脚本使用sendmail
问题描述:
我运行bash脚本cron中当某个条件得到满足将邮件发送给多个收件人。
I'm running a bash script in cron to send mail to multiple recipients when a certain condition is met.
我有codeD这样的变量:
I've coded the variables like this:
subject="Subject"
from="user@domain.com"
recipients="user1@gmail.com user2@gmail.com"
mail="subject:$subject\nfrom:$from\nExample Message"
和实际的发送:
echo -e $mail | /usr/sbin/sendmail "$recipients"
的问题是,只有user2@gmail.com正在接收的电子邮件。我怎样才能改变这种做法,所有收件人收到邮件?
The problem is that only user2@gmail.com is receiving the email. How can I change this so all the recipients receive the email?
请注意:该解决方案必须与sendmail的,我使用的jailshell,它似乎是唯一可用的方法
NOTE: The solution has to be with sendmail, I'm using jailshell and it seems to be the only available method
答
试着做这样的:
recipients="user1@gmail.com,user2@gmail.com,user3@gmail.com"
和另一种方法,使用shell的这里-DOC 的:
And another approach, using shell here-doc :
/usr/sbin/sendmail "$recipients" <<EOF
subject:$subject
from:$from
Example Message
EOF
务必将头从身体以一个空行按 RFC 822 单独>。