Using sendmail from bash script for multiple recipients

一个人想着一个人 提交于 2019-12-02 17:28:56
Gilles Quenot

Try doing this :

recipients="user1@gmail.com,user2@gmail.com,user3@gmail.com"

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.

Use option -t for sendmail.

in your case - echo -e $mail | /usr/sbin/sendmail -t and add yout Recepient list to message itself like To: someone@somewhere.com someother@nowhere.com right after the line From:.....

-t option means - Read message for recipients. To:, Cc:, and Bcc: lines will be scanned for recipient addresses. The Bcc: line will be deleted before transmission.

to use sendmail from the shell script

subject="mail subject"
body="Hello World"
from="me@domain.com"
to="recipient1@domain.com,recipient2@domain.com"
echo -e "Subject:${subject}\n${body}" | sendmail -f "${from}" -t "${to}"
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!