f0dder has asked for the wisdom of the Perl Monks concerning the following question:

I got a perlscript that generates numeric data and emails it to an entire department. My original problem was how to format the email so that the columns of numbers lined up correctly.
Laugh, I thought it was easy too. Wait till you get a taste of proportional font vs fixed with font. Persons with Older Eudora recieved the report and it looked fine because their client defaulted to Courier. Newer Eudora uses proportional font (Arial) causing the data to not line up correctly. Problem solved, I wrapped the data in the following bit of HTML code. Older users of Eudora see's the HTML tags but they're cool with it.
<html><head></head> <body> <tt><pre> ..data Total Hits Misses Delta A 71 22 49 +22 B 3 2 1 +2 C 0 0 0 +0 ..yet more data </pre></tt> </body> </html>
The problem now lies with upper management (the ones that do my review). They're using Outlook and the HTML tags bugs them to no end.
Anyone know how I can change my script so that the HTML will render in MS Outlook? I know MS Outlook can do it. Viewing the source of Outlook mail they've got a bunch of XML like tags. But I can't get them to work.

Replies are listed 'Best First'.
Re: How to format email so Outlook renders HTML
by tachyon (Chancellor) on Aug 29, 2001 at 03:00 UTC

    You should check out this thread which answers just this problem. Multi-Part email with Attachments using MIME::Lite The key words are 'multipart/alternative' and 'Mime' if you want to do a search. The long and the short of it is that a multipart/alternative MIME format email has a plain text bit and an HTML bit. If the email client can do HTML it displays the HTML, if not it displays the plain text. This will fix your problem. There is full code at the above node. If you want to add a Word doc, XL file or even a Powerpoint slide you can do that to with the code presented.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      I've had to do this before and I found Mime::Lite to be extremely helpful.

      If you just want to send the html as the body of the e-mail just omit the part of the above mentioned tutorial that inserts the text/plain portion.

      But I caution you, only send this to people that you know have the right mail client to handle it or you may have some irate plain text email users on your hands!
      --
      Clayton aka "Tex"

        MIME::Lite is definately the way to go. Take a look at the examples...

        One solution to the plain text/html quandry is to include a text/plain message first and then the text/html so that your email message looks something like:
        multipart/mixed
        - text/plain
        - text/html

        ### Create the multipart "container":
            $msg = MIME::Lite->new( 
                         From    =>'me@myhost.com',
                         To      =>'you@yourhost.com',
                         Cc      =>'some@other.com, some@more.com',
                         Subject =>'A message with 2 parts...',
                         Type    =>'multipart/mixed'
        		 );
            
            ### Add the text message part:
            ### (Note that "attach" has same arguments as "new"):
            $msg->attach(Type     =>'text',   
                         Data     =>$text_msg,
        		 );  
             
            ### Add the HTML part:
            $msg->attach(Type     =>'text/html',
                         Data     =>$html_msg,
        		 );
        
        Oren
Re: How to format email so Outlook renders HTML
by dondelelcaro (Monk) on Aug 29, 2001 at 02:58 UTC
    Outlook seems to need to have the content type set correctly in order for it to view a page as html with html tags.

    You might be able to do this by adding the <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> tag, but your best bet is to check out MIME::Lite and generate a multi-part mime document. That should enable you to get the fixed-width in proportional e-mail clients that you were looking for.
(MeowChow) Re: How to format email so Outlook renders HTML
by MeowChow (Vicar) on Aug 29, 2001 at 06:00 UTC
    A simple hack would be to add the following header to your emails:
    content-type: text/html
    The correct and comprehensive solution has already been suggested by tachyon, however.
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
      I am gonna pursue tachyon's suggestion. The earlier suggestions didn't work (adding the content-type and adding the <!DOCTYPE HTML PUBLIC.... ). As they ended up being displayed in the body of the email text.

      I really do appreciate all of the suggestions and thus I'd like to share this (it's been around but I just found out about it and love it). On NT & Win2k you can enable autocomplete (ie think of bash)in the command window by changing the following reg key
      In HKEY_CURRENT_USER|Software|Microsoft|Command Process double click on CompletionChar and change the value to 9.
      When you run cmd on win2k type the first 2 unique char and hit tab to autocomplete the text.
Re: How to format email so Outlook renders HTML
by Beatnik (Parson) on Aug 29, 2001 at 14:08 UTC
    Did anyone mention MIME::Lite::HTML yet??

    Example:
    use MIME::Lite::HTML; my $mailHTML = new MIME::Lite::HTML From => 'foo@bar.org', To => 'bar@foo.org', Subject => 'Mail in HTML with images'; $MIMEmail = $mailHTML->parse('http://www.perlmonks.org'); $MIMEmail->send; # or for win user : $mail->send_by_smtp('smtp.foo.org +');

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: How to format email so Outlook renders HTML
by mr.dunstan (Monk) on Aug 29, 2001 at 10:42 UTC
    Make this feature platform-non-specific by emailing a link instead of the data - that way you know for sure they're looking at the html in a browser instead of numerous, various email clients.

    My 2 quatloos,

    -mr.dunstan
Re: How to format email so Outlook renders HTML
by blakem (Monsignor) on Aug 29, 2001 at 02:28 UTC
    Have you tried the <CODE> tags? (toungue planted firmly in cheek)

    -Blake

      yes i have. Gettin pretty good at getting perl to parse web pages generated by gnats :) for making reports.