Operating System - Linux
1752790 Members
6441 Online
108789 Solutions
New Discussion юеВ

Re: Subject line with the sendmail command

 
trilok_pvp
Frequent Advisor

Subject line with the sendmail command

Hi All,

I want to send a mail from command line, I am using sendmail command for the same.

I tried sending mails to myself. I am able to send mails but, i don't know how to specify Subject line.

echo "Disk Report of `hostname` as of `date`" 2> /dev/null > diskreport
df >> diskreport
sendmail " trilok.prasad@gmail.com < diskreport

How can Subject line be specified?

Thanks
Trilok PVP
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor

Re: Subject line with the sendmail command

Hi:

# mailx -s "Disk Report for $(hostname)" myemail@mycompany.com < diskreport

Note the '-s' argument and the use of 'mailx'.

Regards!

...JRF...
trilok_pvp
Frequent Advisor

Re: Subject line with the sendmail command

Hi

The mailx is working in hp unix servers, same scripts with mailx -s is working in hp unix servers. mailx is not working in linux postfix relay pc. sendmail is working and i am getting the mail without subject.
James R. Ferguson
Acclaimed Contributor

Re: Subject line with the sendmail command

Hi (again):

Sendmail isn't intended at a user interface. You can type, line-for-line something like:

sendmail myemail@mycompany.com
Subject: myrepot
This is the body of my message
^D

...Note the line that begins with "Subject:" triggers the subject line. The ^D is a control_D which signifies end-of-file.

Regards!

...JRF...
Steven E. Protter
Exalted Contributor

Re: Subject line with the sendmail command

Shalom Trilok,

http://www.hpux.ws/?p=6

Take a look at the script in there. It is a bit more than you need but demonstrates how to control the subject.

You can also use the script to attach a file to an email, delivering your report that way.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: Subject line with the sendmail command

Hi Trilok:

OK, this works:

#!/bin/sh
sendmail myemail@mycompany.com <<- EOF!
> Subject: Disk Report from $(hostname)
> $(< /tmp/diskreport)
> EOF!

Again, make sure that the line that begins with "Subject" specifies an uppercase "S" and a colon (:) character as shown.

Regards!

...JRF...
Modris Bremze
Esteemed Contributor

Re: Subject line with the sendmail command

For similar purposes I would use something like this (one line):

/usr/bin/printf "%b" "Subject:subject goes here\nFrom:specify.from@address.com\n" $(cat diskreport) | /usr/sbin/sendmail your@mail.com

The $(cat diskreport) will fill the message body. It is possible to substitute it with plain text or other command if required.
Stephen P. Schaefer
Frequent Advisor

Re: Subject line with the sendmail command

The "Subject:" is a header field in an RFC822 e-mail message; a blank line should separate the body of the message from the headers.
Court Campbell
Honored Contributor

Re: Subject line with the sendmail command

not sure what distro you are using, but if you like mailx you can install it. If this is rhel you can either

up2date -i mailx

or

yum install mailx
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"