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\nfrom:$from\nExample 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
Run `mail' command by '-s' option with email subject and the recipient email address like the following command. It will ask for Cc: address. If you don't want to use Cc: field then keep it blank and press enter. Type the message body and press Ctrl+D to send the email.
If you want to use smtplib to send email to multiple recipients, use email. Message. add_header('To', eachRecipientAsString) to add them, and then when you invoke the sendmail method, use email.
Another way to send email messages on a Linux system is by using the “sendmail” command. This is one of the most common email-sending commands used by Linux system operators. However, you will have to install the “sendmail” program to be able to run this command.
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.
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: [email protected] [email protected]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With