?
Solved

UNIX sendmail not working properly

Posted on 2011-03-14
8
Medium Priority
?
382 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

762 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