Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

UNIX sendmail not working properly

Posted on 2011-03-14
8
Medium Priority
?
384 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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
 
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 1900 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

#Citrix #POC #XenDesktop #vCenter #VMware #ESX
I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.
Suggested Courses

604 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