Solved

UNIX sendmail not working properly

Posted on 2011-03-14
8
376 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux Mailserver setup & redundancy 2 83
rsyslog raw message 4 38
UM7 Stop Sending packets with GPS Sensor 1 21
database connection error mysql stops 7 35
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

730 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