简体   繁体   中英

mailx sending email to multiple accounts

I am trying to use mailx to send an email via shell script.

Message=<HTML><BODY><p>FINISHED</p></BODY></HTML>

Recipients=email1@email.org;email2@email.org
Recipients=$(echo "${Recipients}" | sed "s/;/ /g")
echo "Recipients:  ${Recipients}"

mailx -s "Ingestion Report ${EXT1}. $( echo "\nContent-Type: text/html")" "${Recipients}" < $MESSAGE

my problem is I'm trying to change the list delimited by a semi-colon to a space-delimited list because I"m told that is what's needed by mailx.

However, the response is:

sh: email2@email.org:  not found

what am I doing wrong? thanks.

A semicolon is a command separator, so you have to change how you are defining Recipients from:

Recipients=email1@email.org;email2@email.org

To:

Recipients="email1@email.org;email2@email.org"

Quoting the value prevents the ; from being interpreted as a command separator.

Alternatively, you can just define Recipients correctly in the first place:

Recipients="email1@email.org email2@email.org"

Or if you don't control that for whatever reason, you can drop the sed call and just do:

mailx ... ${Recipients/;/ }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM