Operating System - HP-UX
1821589 Members
3377 Online
109633 Solutions
New Discussion юеВ

send e-mail from command line add subject how to

 
SOLVED
Go to solution
jamesps
Regular Advisor

send e-mail from command line add subject how to

I am trying to set my server to automatically send some emails out. What I would like to do is to create a "Subject" field. I read the sendmail's man page but cannot find any reference to such a thing. How can it be done?

I can do this from command line just fine:
echo "test" | sendmail

The email is sent and received at destination successfully.

The command below sends an e-mail and the address is being put at BCC with no subject and the body contains the word "test". All I need is to add a Subject field and eventually a To or CC to it. Please help.

Thank you!
james
8 REPLIES 8
jamesps
Regular Advisor

Re: send e-mail from command line add subject how to

by "the command below" I meant "the above command", sorry too tired I guess :)
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: send e-mail from command line add subject how to

elm can be driven from the command line:

echo "test" | elm -s "Test Subject" admin@xyz.com.

Unlike the interactive version of elm (which will create it automatically), you must have a .elm directory (it can be empty) in the sender's home directory. Man elm for details.
If it ain't broke, I can fix that.
Rick Garland
Honored Contributor

Re: send e-mail from command line add subject how to

echo test | sendmail -s "This is the subject" you_address.com


This will work as well.

mailx -s "This is the subject" you_address.com < test


Alan Meyer_4
Respected Contributor

Re: send e-mail from command line add subject how to

As can mailx
echo "test" | "mailx" -s 'test subject' admin@xyz.com
" I may not be certified, but I am certifiable... "
jamesps
Regular Advisor

Re: send e-mail from command line add subject how to

I can't believe it was that simple. Actually it wasn't because I can't do it with sendmail. Sendmail seem to not like the "-s" parameter. I've been through its man page and have not found anything to use to get a subject or change the To or CC.

Since elm needs a directory "to work" mailx is the way to go for now.
Thank you all!

james.

PS: shouldn't sendmail have some "hidden" option to send a subject?!
Patrick Wallek
Honored Contributor

Re: send e-mail from command line add subject how to

I use the following with the sendmail command in a script:

(echo "Subject: e-mail subject here" ; echo "test") | sendmail admin@xyz.com



Mel Burslan
Honored Contributor

Re: send e-mail from command line add subject how to

Patrick's solution works. Just make sure you send a "\n" (new line characher) at the end of your subject string to insert a blank line to separate the header (which subject line is a part of along with many others you can inject into) from the message body.

HTH
________________________________
UNIX because I majored in cryptology...
jamesps
Regular Advisor

Re: send e-mail from command line add subject how to

Yes it works. Thanks Patrick!

Mel, I am not sure I understand, is there a \n needed if I need to put a "To: ..." line for example?

Thanks all!
james