On Sun, Feb 02, 2003 at 07:54:31PM -0800, Palit, Nilanjan wrote:
> This question is not directly related to Perl, but I'm hoping that someone here can 
>answer it.
> 
> I have written a tool in Perl, that runs on Unix, to generate daily roll-up reports 
>and mail it out to a distribution list. Most of the recipients use Microsoft Outlook 
>to read the reports. I have received several requests for formatting the message, 
>e.g. with bold or italic or colored or different sized fonts, to make it more 
>readable. I have very few ideas on how to go about doing that. One option may be to 
>generate (via Perl) a HTML formatted message. But how would I get Outlook to 
>recognize that as a HTML message and not  a plain text message? Any ideas would be 
>greatly appreciated.

I haven't seen any propose module-based solutions, so here is a copy &
paste from some code I wrote before. You'll have to get creative and
work out what's going on, but it provides the option to send plain-text,
html only, and both.

Needs:

use Template ();
use MIME::Entity ();

Code fragment,

    my $top = MIME::Entity->build(
        Type     => 'multipart/alternative', # XXX this is a bit of a hack since we 
may only send one part
        From     => 'Robot <[EMAIL PROTECTED]>',
        To       => "$user_info->{name} <$user_info->{email}>",
        Subject  => "Report for $user_info->{name}",
    );
    
    my $report_format = $user_info->{prefs}{report_format}
        or die "No report_format set in userprefs!";
    if ($report_format ne 'text/html') {
        my $output;
        $template->process("email.txt", $params, \$output)
            or die $template->error;
        $top->attach(
            Type     => 'text/plain',
            Data     => $output,
            Encoding => 'quoted-printable'
        );
    }
    if ($report_format ne 'text/plain') {
        my $output;
        $template->process("email.html", $params, \$output)
            or die $template->error;
        $top->attach(
            Type     => 'text/html',
            Data     => $output,
            Encoding => 'quoted-printable'
        );
    }
    
    # For reasons unclear, ->send() loses the content-type: headers :-/
    $top->smtpsend;

It's not optimal; you may want to send a direct text/plain message
without the multipart cruft but frankly I've yet to see an MUA that
can't deal with it.

HTH,
Paul

-- 
Paul Makepeace ....................................... http://paulm.com/

"What is the colour red? Pins and needles. No more. No less."
   -- http://paulm.com/toys/surrealism/
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to