Operating System - HP-UX
1819766 Members
3054 Online
109606 Solutions
New Discussion юеВ

Re: Script to send HTML email

 
SOLVED
Go to solution
Marty Metras
Super Advisor

Script to send HTML email

I have scripts that check logs and files that users need to be alerted to and it email them a message.
What I wanted to do is send the emails like an html document so I could add some color to it so they might know how fast they need to look at it.
Using shell script to create a HTML attachment is easy.
What I do not know is how code it so when I send it and the uses opens the email it is a html document.
After searching the web I find a lot of package that do this. I don't want to any thing fancy. Besides I have fun writing little scrpts that do neat things.

Normally I just use "mail -s "Alert Message" userID What would be needed if this message was HTML.

Marty
The only thing that always remain the same are the changes.
12 REPLIES 12
Mark Greene_1
Honored Contributor

Re: Script to send HTML email

The mail client the recipient is using should detect the html in the message automatically, and then display it accordingly.

You can try using uuencode with it, but I don't belive it would be needed.

mark
the future will be a lot like now, only later
Marty Metras
Super Advisor

Re: Script to send HTML email

When I email a HTML document it comes through as html code.

I am sending the file like this. (Typo above)

mailx -s "test html message marty"
There has to be a way to tag the html file taht is an html so the client software will display it.
I use outlook and it open other html emails but I do not see how it knows to do so.

Marty
The only thing that always remain the same are the changes.
Oviwan
Honored Contributor

Re: Script to send HTML email

Hi

instead of html formatted you can use the command "banner" to generate your message-file. i don't know whether it helps you.

Regards
Marty Metras
Super Advisor

Re: Script to send HTML email

I know about banner.
I do that now with some of the messages.
I thought the might be an easy to send a hrml file the would open right up without being an attachment.
I just wanted to try to get a little fancy.
Marty
The only thing that always remain the same are the changes.
Dave La Mar
Honored Contributor

Re: Script to send HTML email

Marty -
We have many jobs that do this, sending the HTML as an attachment to a user on Outlook from our 11.0 machines.

This is the mailx command used -

uuencode ${OUTPUT_FILE} "Netbackup Daily Report_${Yesterday}.html" | $MAIL -s "Netbackup Nightly Jobs Report For ${YDATE}" ${ADDRESS}

If the variables are not clear to you I can give the same example with the actual values but OUTPUT_FILE=the unix html file, YDATE is a formated date for yesterday as is Yesterday [different formats], ADDRESS is the recipient email address.

Best of luck.

Regards,

dl
"I'm not dumb. I just have a command of thoroughly useless information."
Geoff Wild
Honored Contributor

Re: Script to send HTML email

Do you want it embedded or as an attachement?

I prefer attachements.

Download and install mpack:

http://hpux.ee.ualberta.ca/hppd/hpux/Users/mpack-1.6/

Run like so:

/usr/local/bin/mpack -s "svr004 cfg2html" /opt/cfg2html/svr004.html gwild@mydomian.ca

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Marty Metras
Super Advisor

Re: Script to send HTML email

Attachments are easy.
I guess what I want is an embedded html email.

Marty

The only thing that always remain the same are the changes.
Geoff Wild
Honored Contributor

Re: Script to send HTML email

I think the only way to send embdded html is via Perl - you will need to write a script...

I did find this via google - that may help:

http://willmaster.com/possibilities/archives/wmp20020716001.shtml

There is an example cgi script...look at the "sub SendEmail" section...

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Geoff Wild
Honored Contributor

Re: Script to send HTML email

Tested the following - it works:

http://caspian.dotconf.net/menu/Software/SendEmail/

It is quite a large script...

To send html embeded:

cat /path/to/somefile.html | sendEmail.pl -f from@email.address -t to@email.address -u "Your Subject"

The html file must start with

If sendmail isn't running as a daemon on the localhost, then modify the line in the script from localhost to your email server:

"server" => 'localhost', ## Default SMTP server


Rgds..Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Jean-Yves Picard
Trusted Contributor
Solution

Re: Script to send HTML email

Hello,

a bit late, but maybe ...
mail should start with

To: auser@mycompany.com
CC: anotheruser
Subject: report
Content-Type: text/html
<- a blank line

...

then pipe to /usr/lib/sendmail -t

I didn't details sending file as attachement as you find it too easy ;-)

Jean-Yves
Marty Metras
Super Advisor

Re: Script to send HTML email

Great Jean-Yves

It is easy after all.
I just add "Content-Type: text/html"
and a blank line to the top if the a HTML file and send it.
It is more involved with links and graphics but I am not planning any of that.

Thanks again.
Marty
The only thing that always remain the same are the changes.
Geoff Wild
Honored Contributor

Re: Script to send HTML email

Or, instead of adding to a file, just do this:

echo "To: you@yourdomain.com\nSubject: your subject\nContent-Type: text/html\n\n"`cat /path/to/somefile.html` | sendmail -t

Works like a charm :)

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.