Solved

UNIX sendmail not working properly

Posted on 2011-03-14
8
373 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Video Streaming 6 75
how can I get powershell to show the history of commands used ? 10 56
Penetration Testing home based work 3 76
Windows 8.1 HP issues 11 29
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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 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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

831 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