Solved

UNIX sendmail not working properly

Posted on 2011-03-14
8
371 Views
Last Modified: 2012-05-11
I write the attached notification email in UNIX shell script on Solaris10 server. The email that I receive only shows the subject correctly but the Body of the email is blank. What am I doing incorrectly?
#!/bin/sh
    tmp=/tmp/mail-body-`date +%F`;
    touch $tmp && chmod 600 $tmp;
    TO='me@myco.com';
    CC='me@myco.com';
    FROM='me2@myco.com';
    SUBJECT='ETL JOB2';
    MIMEVersion='1.0';
    CONTENTType='text/html; charset=us-ascii';
    BODY='ETL successfully completed';

    echo Sending the mail.
    echo -e "To: $TO" > $tmp;
    echo -e "Cc: $CC" >> $tmp;
    echo -e "From: $FROM" >> $tmp;
    echo -e "Content-Type: $CONTENTType">>$tmp;
    echo -e "MIME-Version: $MIMEVersion">>$tmp;
    echo -e "Subject: $SUBJECT">>$tmp;
    echo -e "Body: $BODY">>$tmp;

    /usr/sbin/sendmail -t < $tmp;

    rm -rf $tmp;

Open in new window

0
Comment
Question by:toooki
  • 4
  • 3
8 Comments
 
LVL 4

Expert Comment

by:subratabiswas
ID: 35135605
Try to insert a blank line before the body.

"Body:" tag is not required.
0
 
LVL 4

Expert Comment

by:subratabiswas
ID: 35135614
If you add "Body:" in the message, that string will also be included in the message. What is required is a blank line after the "Subject:" and before the actual message body.
0
 
LVL 14

Expert Comment

by:sentner
ID: 35138641
Looks like you're overcomplicating things.  You don't need to set a mime type, or content type.  As subratabiswas said, just put a blank line between the subject and body.  

    echo "To: $TO" > $tmp;
    echo "Cc: $CC" >> $tmp;
    echo "From: $FROM" >> $tmp;
    echo "Subject: $SUBJECT">>$tmp;
    echo >>$tmp
    echo  "$BODY">>$tmp;

0
 

Author Comment

by:toooki
ID: 35153749
Many thanks for all the help.
    echo -e "Subject: $SUBJECT">>$tmp;

    echo -e "Body: $BODY">>$tmp;


Just adding the extra blank line between the above two lines worked.
But actually I have been trying to put the content of one text file into the $BODY variable.
I tried

    /bin/cat /usr/home/w12345/templog.txt >> $BODY
    echo -e "Body: $BODY">>$tmp;

But cannot make it work. What is the correct syntax here? Thanks.
   
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 4

Expert Comment

by:subratabiswas
ID: 35154440
You are trying to assign the contents of the whole file into the vriable and then trying the echo that variable into the mail file. Instead, do the straight and easy way; just cat the content of the file into the mail file

echo "To: $TO" > $tmp;
echo "Cc: $CC" >> $tmp;
echo "From: $FROM" >> $tmp;
echo "Subject: $SUBJECT">>$tmp;
echo >>$tmp
/bin/cat   /usr/home/w12345/templog.txt   >>   $tmp
0
 

Author Comment

by:toooki
ID: 35178053
Thank you..

Yes the
/bin/cat   /usr/home/w12345/templog.txt   >>   $tmp

works somewhat..

Problem is that the email content cannot recognize the newline characters in the templog.txt file. So the contents of /usr/home/w12345/templog.txt  come as single line in the email.

If I echo >>$tmp it shows the contents correctly.

So I need to make some changes in the email header ??
CONTENTType='text/html; charset=us-ascii';  ??

The email I receive is in HTML format (gmail).
 
0
 
LVL 4

Accepted Solution

by:
subratabiswas earned 475 total points
ID: 35178584
If you decide to send HTML and maintain the typed format, you may use <PRE> tag around the message body; HTML by itself processes whitespaces in its own way.

You may consider removing content type from the email header altogether. It does not make sense to indicate message type = 'HTML' and not having a real HTML body.
0
 

Author Comment

by:toooki
ID: 35317962
It worked finally the way you said. Sorry for delayed reply.
Thank you very much.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now