The following code works when I directly run it in bash
shell:
SUBJECT="SUBJECT-"`date`;
MAIL_FROM="[email protected]";
MAIL_TO="[email protected]";
MAIL_CC="[email protected]";
MAIL_FILE="/path/of/html/body.html";
(echo -e "Subject: $SUBJECT\nMIME-Version: 1.0\nFrom: $MAIL_FROM\nTo:$MAIL_TO\nCc:$MAIL_CC\nContent-Type: text/html\nContent-Disposition: inline\n\n";/bin/cat $MAIL_FILE) | /usr/sbin/sendmail -f $MAIL_FROM $MAIL_TO;
But when I try to run it within a script like below...
Contents of mail.sh:
#!/usr/bin/ksh
SUBJECT="SUBJECT-"`date`;
MAIL_FROM="[email protected]";
MAIL_TO="[email protected]";
MAIL_CC="[email protected]";
MAIL_FILE="/path/of/html/body.html";
(echo -e "Subject: $SUBJECT\nMIME-Version: 1.0\nFrom: $MAIL_FROM\nTo:$MAIL_TO\nCc:$MAIL_CC\nContent-Type: text/html\nContent-Disposition: inline\n\n";/bin/cat $MAIL_FILE) | /usr/sbin/sendmail -f $MAIL_FROM $MAIL_TO;
I get the following results...
$ sh mail.sh #Mail sent but the body is in text format containing "-e Subject: SUBJECT-Wed Jan 30 04:45:42 EST....."
and the HTML code rendered as text.
$ bash mail.sh # Mail is received with mail body containing correct HTML format.
So it seems that echo -e
is recognized by bash. But when I use "#!/usr/bin/bash" and run the script as $ sh mail.sh
I still get a mail in text format.
Why is this so..? Thanks in advance for your suggestions.