1819796 Members
3117 Online
109607 Solutions
New Discussion юеВ

mailx to send html mail

 
SOLVED
Go to solution
kholikt
Super Advisor

mailx to send html mail

I am written some script to mail some report to my mailbox.

I want to send the mail in html format but end up it show all the HTML source in my outlook. Apart from that I also notice the case statement didn't work at all. No matter it is friday or saturday all mail seem to send using the SEND_TO instead of SEND_TO_WEEKEND

DAY=`date '+%A'`

case $DAY in
Monday|Tuesday|Wednesday|Thursday|Friday)
mailx -r $SEND_FROM -s $REPORT_TITLE $SEND_TO < $FILE ;;
Saturday|Sunday)
mailx -r $SEND_FROM -s $REPORT_TITLE $SEND_TO_WEEKEND < $FILE
esac
abc
5 REPLIES 5
kholikt
Super Advisor

Re: mailx to send html mail

Apart from this, in the shell script How could I put those special character.

For example

MYVAR=ABC/BCD

MYVAR="bgcolor ="#ffffff""
abc
generic_1
Respected Contributor
Solution

Re: mailx to send html mail

Try

DAY=`date '+%A'`
case "$DAY" in
Monday|Tuesday|Wednesday|Thursday|Friday)
mailx -r $SEND_FROM -s $REPORT_TITLE $SEND_TO < $FILE
;;
Saturday|Sunday)
mailx -r $SEND_FROM -s $REPORT_TITLE $SEND_TO_WEEKEND < $FILE
;;
esac

Enclose Day as shown basically and put the ;;
on the following line is the difference. Also you did not terminate your second case.
Elmar P. Kolkman
Honored Contributor

Re: mailx to send html mail

I think Jeff's solution for the case statement should solve your issue. Also don't forget the double semicolon for the second switch. And perhaps add a default switch, just in case you have a locale problem, resulting in strange DAY values.

As for the other problem, you might need to add some lines so that Outlook understands it is HTML. It has to be something like this:
content-type: text/html
This has to be the top line. To be sure it is parsed correctly, also add 2 blank lines after the content-type line.

The problem is, mailx already creates a content-type line. The command mail doesn't, but will not create a subject. This can be solved by adding a -m option, which will not put in the MIME type of the message. Also, you still need to insert the content-type in the header. Putting it in as first line in the text, doesn't work... But there is a solution I found:

mailx -m -r $SEND_FROM -s "$REPORT_TITLE
Content-type: text/html" $SEND_TO <$FILE

should work... The new-line in the subject is accepted by mailx, and will put the content-type on a new line in the header, which Outlook will accept...

Not the nicest solution, but this works with the tools you have, at least.

But perhaps it's time to think about other, more suitable tools...
Every problem has at least one solution. Only some solutions are harder to find.
Dave La Mar
Honored Contributor

Re: mailx to send html mail

Greetings -
We send several html reports daily, but do so using mailx. The attachment comes in through Outlook as an html without problem.

i.e.
uuencode OUTPUT_FILE.html OUTPUT_FILE.html | mailx -s "Netbackup Nightly Jobs Report" somone.ofinterest@somewhere.com

I believe your case statement problem has already been addressed.

Best regards,

dl
"I'm not dumb. I just have a command of thoroughly useless information."
David Nardi
Advisor

Re: mailx to send html mail

I send myself an HTML doc of system stats daily using sendmail. I won't litter up the forum with yet another stats recorder, but if you're interested in the whole stats file email me and I will send it to you.

The var $TMPFILE is the file with all the stats information as well as embedded html codes.

I create a header file to pass to sendmail with the routing information. The Content-type line tells my email client that this is an html doc, and to display it as such in my quick view window. I don't have to open each email to actually view it, I can just hightlight the subject line and read the message body.

echo "To: sysadm
Subject: $TMPFILE
Content-type: text/html; charset=us-ascii
MIME-Version: 1.0

" > $HEADERFILE;
(cat $HEADERFILE; cat $TMPFILE) | /usr/sbin/sendmail -t -v;

Be sure to have a blank line at the end of the header file.

Hope this helps...