Messaging
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the Exit Status in sendmail.

Raghu Chikkamenahalli
Frequent Advisor

How to get the Exit Status in sendmail.

Hi All,

I have written small shell script which sends an e-mail using sendmail command.
Need to check the exit status after the completion of the sendmail.

Read the "sendmail" manpage and found some of the exit status defined. But I am unable to caputre the exit status using the "$?". Kindly guide how to capture the same.

Here is my Script

echo "To: raghu@xyz.com " > mesg
echo "From: raghu@abc.com" >> mesg
echo "Subject: Mail using sendmail" >> mesg
echo "Content-type: mixed/multipart base64;"
echo "" >> mesg
echo "Message file attached" >> mesg
echo "" >> mesg

cat mesg|/usr/sbin/sendmail -t

echo $?

Regards,
Raghu
5 REPLIES
James R. Ferguson
Acclaimed Contributor

Re: How to get the Exit Status in sendmail.

Hi:

Your script worked (and returned valid exit codes) for me. As you know, the possible exit values are defined in the manpages and can be mapped from '/usr/include/sysexits.h'.

For example if I use a recipient of "me" in the "To" line, I see an exit value of 67 (EX_NOUSER).

For efficiency, eliminate your 'cat' and write:

/usr/sbin/sendmail -t < mesg

Regards!

...JRF...
Raghu Chikkamenahalli
Frequent Advisor

Re: How to get the Exit Status in sendmail.

Hi JRF,

Thanks for the reply.
This works for the id which doesnot have the @domainname.
Is it possible to get the status if an invalid email id eg. raghu@123.com
(which does not exists) in the To: field is given...
Regards,
Raghu.
Dennis Handly
Acclaimed Contributor

Re: How to get the Exit Status in sendmail.

>Is it possible to get the status if an invalid email id eg. raghu@123.com (which does not exists) in the To: field is given.

You can always get the status. But errors in delivery are probably not detected in sendmail but by the bounced mail message.
Steven E. Protter
Exalted Contributor

Re: How to get the Exit Status in sendmail.

Shalom,

You might want to see mail.log file. You can turn up the log level if you need increased detail to track a scripting problem by changing sendmail.cf and restarting sendmail.

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: How to get the Exit Status in sendmail.

Hi (again) Raghu:

> Is it possible to get the status if an invalid email id eg. raghu@123.com
(which does not exists) in the To: field is given...


Errors like that, as noted, will probably be reported not as a return status, but as an undeliverable message noted in '/var/adm/syslog/mail.log'.

The manpages and the contents of '/usr/include/sysexits.h' will describe what return codes AND the reason they may be returned. I suggest examining them.

Regards!

...JRF...