Unable to recieve email using sendmail

Hi, Here is my script to send out emails.

#!/bin/ksh

{
        print "From: Prod@`hostname`.mycomp.com"
        print "To: me@mycomp.com"
        print "MIME-Version: 1.0"
        print "Content-Type: text/html"
        print "Subject: Usage Report"
        print ""
        print "<html>"
        print "<body>"
        print "<p>Today Usage Report for Server</p>"

        print "</body>"
        print "</html>" } | /usr/sbin/sendmail -t

This script runs but i do not receive any email to my email address me@mycomp.com.

uname -a SunOS myhost 5.11 11.3 sun4u sparc SUNW,SPARC-Enterprise

Can you please suggest how can i debug and fix the problem ?

---------- Post updated 04-25-17 at 02:47 AM ---------- Previous update was 04-24-17 at 05:07 PM ----------

Here is all of my troubleshooting.

ps -ef|grep -i sendmail|grep -v grep
   smmsp  6755  4646   0   Apr 20 ?           0:01 /usr/lib/inet/sendmail -Ac -q15m
    root  6757  4646   0   Apr 20 ?           0:11 /usr/lib/inet/sendmail -bl -q15m

mailx does not work as you can see below.

 mailx -s "test messages from unixrock" me@mycomp.com


^C     <---- Pressed Ctrl+C to terminate as i did not get any output after a while
(Interrupt -- one more to kill letter)
^C"/export/home/user1/dead.letter" 4/4

/var/adm/messages is empty ... there is no logging there.

ls -ltr /var/adm/messages
-rw-r--r--   1 root     root           0 Apr 14 03:10 /var/adm/messages

Checking mail relay server in /etc/mail/submit.cf

grep DS /etc/mail/submit.cf
DS
# Return-Receipt-To: header implies DSN request
# DHParameters (only required if DSA/DH is used)

Checking whether mail port (port 25) is listening. It indeed is.

telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 mymac ESMTP Sendmail 8.15.1+Sun/8.15.1; Tue, 25 Apr 2017 03:00:26 -0500 (CDT)

The strange thing is that this server does send out emails which are set in crontab and does not when i m trying to manually run the crontab scripts.

Its more like intermittent behavior.

Important Note: A strange observation: while mailx command shown above does not work BUT the below mailx command works fine and WE do receive emails.

mailx -s "test messages from unixrock" me@mycomp.com < /etc/hosts

Can you please guide me to get this to work or debug the root cause ?

All of the above makes me believe there is something not write with our test.sh our code in the OP.

I further trimmed down my test.sh script as you see below.

#!/bin/ksh  
{         
print "From: Prod@`hostname`.mycomp.com"         
print "To: me@mycomp.com"         
print "Subject: Usage Report"         
print "<html>"         
print "<body>"         
print "</body>"         
print "</html>" 
} | /usr/sbin/sendmail -t

But it still does not work :frowning:

If someone can point that out ... it will be great.

Please suggest.

The command:

mailx -s "test messages from unixrock" me@mycomp.com < /etc/hosts

works while the command:

mailx -s "test messages from unixrock" me@mycomp.com

hangs because the mailx command reads the text to be sent as the body of your message from standard input. When you type the second command above it is sitting there waiting for you to type in the text to be sent.

If you type in the text that you want to be the body of your message after entering the 2nd command above and then hit Ctl-D to terminate the message, the command should do what you seem to expect.

True.. while i understand that > the main problem is with the OP test.sh script.

---------- Post updated at 09:40 AM ---------- Previous update was at 05:22 AM ----------

I got the line causing the email to fail and not showup in my inbox.

I changed this line test.sh From

        print "From: Prod@`hostname`.mycomp.com" 

to

        print "From: me@mycomp.com"

and now it works.

Can you tell me why is this line print "From: Prod@`hostname`.mycomp.com" FAILS to send out emails and what is the FIX ??