Operating System - HP-UX
1834346 Members
2220 Online
110066 Solutions
New Discussion

How to specify List of addresses in mailx

 
SOLVED
Go to solution
Gulam Mohiuddin
Regular Advisor

How to specify List of addresses in mailx

I run one script through cron, which checks for some conditions and sends E-mail message to me.

If condition=TURE then
echo ?No Errors? | mailx ?m gulam@regionpeel.on.ca
fi

Now I want to send this message to 12 more persons.

Please let me know what is the easiest way to send this message to list of different recipients from this script.
Everyday Learning.
5 REPLIES 5
Rainer_1
Honored Contributor

Re: How to specify List of addresses in mailx

simply add the mail addreses to mailx ie.
maix -m user1@domain user2@domain user3@domain ...
Lasse Knudsen
Esteemed Contributor

Re: How to specify List of addresses in mailx

Do like any other Unix command.

mailx -m mailaddress1 mailaddres2 mailaddress3 ..........
In a world without fences - who needs Gates ?
federico_3
Honored Contributor

Re: How to specify List of addresses in mailx

You could also do like this:
let's guess you have a file containing all the users addresses -> FILE=/tmp/file_addresses


while read -r i
do
echo "whatever you want" | mailx -s "SUBJECT" $i
done < $FILE

I hope this helps

federico
Kofi ARTHIABAH
Honored Contributor
Solution

Re: How to specify List of addresses in mailx

David:

If you want to be able to manage the address list from the aliases file, it might be easier to create an alias in the /etc/mail/aliases file ... do the following:

# echo "notifylist: addr1@mydomain.com, addr2@mydomain.com, addr3@mydomain.com, etc" >> /etc/mail/aliases
# newaliases

your line should read

echo $MESSAGE | mailx notifylist

This way if you need to remove someone from the list, you do not have to muck around with the crontab :) Plus you can reuse the list anywhere you would normally use an address!
nothing wrong with me that a few lines of code cannot fix!
Kevin Ernst
Regular Advisor

Re: How to specify List of addresses in mailx

You might find a little more flexibility in terms of what headers you can add to the outgoing message (for instance: don't think you can CC: using mailx from the command line) by using sendmail instead.

Actually, I take that back: you *can* add message headers to the file or 'here' document used to feed mailx, but they will be separated from the rest of the headers by a blank line, which will probably confuse some mail user and/or transport agents.

For some reason, mailx insists on sending messages using the character set 'X-roman8,' which our 'company standard' mail client (Outlook--ugh) doesn't seem to understand. This forces you to perform an additional step (open the message in an external editor) just to read mail sent by mailx. It wasn't apparent to me (even after reading the man page) how to go about fixing that, so I prefer to go on using sendmail in shell scripts because It Just Works.

There's some more (marginally useful) information on using 'sendmail' in a shell script in this thread: http://my1.itrc.hp.com/cm/QuestionAnswer/1,1150,0x95fb5f260cafd4118fef0090279cd0f9,00.html . (Sure hope that link works.)