cancel
Showing results for 
Search instead for 
Did you mean: 

Mailx and recipients

SOLVED
Go to solution
John Collier
Esteemed Contributor

Mailx and recipients

I'm thinking this will be an easy one for most of you, but it has me stumped.

I???m trying to figure out how to send mail to more than one person using ???mailx??? through a command line only interface without having each person I send it to show up in the ???To:??? section of the final mail (I would like some of them to be in the ???CC:??? section and others to be in the ???BCC:??? section as well).

The syntax I have been using that seems to work well at getting the body of the message out with the proper subject line is:

Echo <-message body-> | mailx ???s ???<-subject->??? <-recipients e-mail addresses->

What do I do to identify which e-mail address goes in which category? Reading the man page on mailx has only made my head hurt and a few more hairs fall out (I can???t afford much more of that!).

Does anybody have the magical answer to my problem (PLEASE!)??
"I expect to pass through this world but once. Any good, therefore, that I can do, or any kindness that I can show to any human being, let me do it now. Let me not defer or neglect it, for I shall not pass this way again." Stephen Krebbet, 1793-1855
9 REPLIES
John Poff
Honored Contributor

Re: Mailx and recipients

Hi,

You could setup an alias in /etc/mail/aliases. We do that for our e-mail from root, and the "To:" field just lists the alias name and not all the individual accounts receiving the message. Just put the entries in /etc/mail/aliases, and then run the 'newaliases' command.

JP
John Collier
Esteemed Contributor

Re: Mailx and recipients

While I'm sure that might work (if I understand it correctly), I don't think that it would be the best answer to my situation. I don't always know who I'm going to mail to and I don't want to have to touch that file each time I want to send to someone new. Isn't there another option (or perhaps I'm not smart enough to understand what you are truly trying to say)?
"I expect to pass through this world but once. Any good, therefore, that I can do, or any kindness that I can show to any human being, let me do it now. Let me not defer or neglect it, for I shall not pass this way again." Stephen Krebbet, 1793-1855
John Poff
Honored Contributor

Re: Mailx and recipients

If you have a set group of e-mail addresses that you want to send to on a regular basis, the alias is a good way to go. If you need to send e-mail to a different group of e-mail addresses each time, the alias may not help you as much. In that case, you might have to setup a shell script that loops and sends e-mail to each person individually. I haven't played with doing that as I've been able to just setup the aliases and send mail using the alias name.

JP
Rich Wright
Trusted Contributor

Re: Mailx and recipients

I don't think that you can do it with mailx, but you can do it with sendmail.
See the attached script for a starting point.

Good Luck
Rich Wright
Simon Hargrave
Honored Contributor

Re: Mailx and recipients

You can do it using tilde commands in your message. For example, if you create a text file called msg.txt containing: -

---

~t to1@home.com
~t to2@home.com
~c cc1@home.com
~c cc2@home.com
~b bcc1@home.com
~b bcc2@home.com
~s Subject line
Message waffle yada yada

---

Then do cat msg.txt | mailx to1@home.com
Then again for each of the addresses.

The ~ commands populate the sendmail header, so the recipients can see where it goes. Then send the same file to each user.
Simon Hargrave
Honored Contributor

Re: Mailx and recipients

Beg pardon. The ~ commands actually specify REAL recipients, that is you only have to execute mailx the once, and it'll send to all addresses specified with the ~ commands.
John Collier
Esteemed Contributor

Re: Mailx and recipients

John,

My recipient list does have a way of changing (but then again, doesn't EVERYTHING in the IT world?) so I don't think that a static alias file would be my correct course of action. Thanks for the input, though.


Rich,

I was already aware of the fact that mailx isn't my best choice, but for the time being it is the one that I am stuck with. I will hold your script for a later day though. I'm sure that I will have a chance to make use of it one of these days. Thanks.


Simon,

Your suggestion intrigues me. What I need now is a little clarification on what you are suggesting.

Let's say that I compose a message like:

echo This is a test message | mailx -s "Test1" ~t me@home ~t meagain@home ~c someone_else@home ~b silent_partner@home.com

Will this accomplish what I need or do I need to put some single or double quotes in there somewhere?

My other goal is to impliment this into an OV NNM aplication, so I would like a single line that I can predefine that will do this.

Am I on the right track or is there more?

"I expect to pass through this world but once. Any good, therefore, that I can do, or any kindness that I can show to any human being, let me do it now. Let me not defer or neglect it, for I shall not pass this way again." Stephen Krebbet, 1793-1855
Kasper Haitsma
Trusted Contributor
Solution

Re: Mailx and recipients

Hi John,

Your suggestion to incorporate the ~t ~c ~b in the recipient list in the command line, will only lead mailx(1) to interpret these as 'extra' recipients of localhost. i.e.:
echo "Hi" | mailx -s "Test" ~t me@home.com ~c you@home.com ~b her@home.com
will resultin a
To: ~t@localhost me@home.com ~c@localhost you@home.com ~b@localhost her@home.com
where the ~-recipients will not resolve, and the other recipients will be exposed.

If you want a single command line, in your OV NNM application, you should call a script, feeding it the info you want to send, and in this script, build the suggested text-file with ~-commands at the start of the text-file for recipient info. Next from the script, you perform the mail command: cat | mailx -s "subject"
next clean up your text-file.
HTH
Kasper Haitsma
Messaging &OVO-Ux Competence Center Engineer
Hewlett Packard Nederland B.V.
It depends
John Collier
Esteemed Contributor

Re: Mailx and recipients

Kasper,

So what you're telling me is that there is truly no way to accomplish what I want to do without creating a script?

Well, I'm sorry to hear that because my script writing abilities rank right up there with my abilities to create world piece, but I am grateful for all of the assistance you and the others have given.

It would appear that I should now be off on my next quest;
The Quest for the Holy E-mail Script!

Thanks to you all and Happy Holidays...
"I expect to pass through this world but once. Any good, therefore, that I can do, or any kindness that I can show to any human being, let me do it now. Let me not defer or neglect it, for I shall not pass this way again." Stephen Krebbet, 1793-1855