Is there a possibility to add multiple e-mails to a single variable so that when the shell script is run, it sends a mail to all the specified emails?
-
u will have to use shell script to get different email ids & run mail command with each email ids. Probably you can use a array variable to store email ids or get it from a file. Click here linkTingrammer– Tingrammer2014-07-04 07:12:34 +00:00Commented Jul 4, 2014 at 7:12
-
1Please edit your question and show us the command you use to send email to a single address.terdon– terdon ♦2014-07-04 08:56:25 +00:00Commented Jul 4, 2014 at 8:56
-
stackoverflow.com/questions/5155923/…Ciro Santilli OurBigBook.com– Ciro Santilli OurBigBook.com2015-12-06 08:06:43 +00:00Commented Dec 6, 2015 at 8:06
Add a comment
|
2 Answers
Assuming you use sendmail or mail in your script (which both expect a comma separated string as list of recipients), you can concatenate the IDs (or directly write them as such a list):
$: recipients="[email protected], [email protected], [email protected]"
or concatenating:
$: base_recipients="[email protected], [email protected]"
$: full_recipients="$base_recipients, [email protected]"
$: echo $full_recipients
[email protected], [email protected], [email protected]
The following would be an example sending a mail with sendmail to 3 different mail IDs:
#!/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
Here's my code using mail array:
MAILADDR=([email protected] [email protected] [email protected])
for i in "${MAILADDR[@]}"
do
echo "Mail test..." | mail -s "Mail test subject..." $i
done