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

I everyone! I've been ask to encode with Quoted-Printable all email we're sending out to our users to ensure that we meet RFC criteria... (the email are in french)

I'm using MIME::Lite to send out the email and MIME::QuotedPrint to encode my subject and body. The problem is that I receive the email and they are not decoded... I see scramble characters. I've tried many thing without any success...

I need your help !!!

my $msg = MIME::Lite->new( 'From' => $emailReturn, 'To' => $email, 'Subject' => $subject, 'Type' => 'text/html', 'Data' => $message, ); $msg->attr('MIME-Version' => '1.0'); $msg->attr('Encoding' => 'quoted-printable'); $msg->attr('content-type' => 'text/html'); $msg->attr("content-type.charset" => "windows-1252"); $msg->send('smtp', "[IP ADRESS]", Timeout=>60);
the $subject and $message variables are the one I'm trying to encode...

20070822 Janitored by Corion: Put code into code tags, as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: Encoded mailing
by talexb (Chancellor) on Aug 21, 2007 at 14:04 UTC
      I'm using MIME::Lite to send out the email and MIME::QuotedPrint to encode my subject and body. The problem is that I receive the email and they are not decoded... I see scramble characters. I've tried many thing without any success...

    Where are you doing this encoding? I don't see this in your code fragment. (By the way, you should use code tags around code -- this helps make it stand out, and also automatically provides a link to allow code download.)

    The CPAN documentation for MIME::QuotedPrint seems to be pretty straightforward: just use the encode_qp method to encode the information. So your fragment should be

    use MIME::QuotedPrint; use MIME::Lite; my $msg = MIME::Lite->new( 'From' => $emailReturn, 'To' => $email, 'Subject' => encode_qp($subject), 'Type' => 'text/html', 'Data' => encode_qp($message), ); $msg->attr('MIME-Version' => '1.0'); $msg->attr('Encoding' => 'quoted-printable'); $msg->attr('content-type' => 'text/html'); $msg->attr("content-type.charset" => "windows-1252"); $msg->send('smtp', "IP ADRESS", Timeout=>60);
    Is that clear?

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      If lbrid is encoding his data separately, then that is where the error is. MIME::Lite handles the encoding itself using MIME::QuotedPrint, so the data would be encoded twice.

      Also, you cannot encode non-ASCII characters in the header using the same techniques as for the data. As specified in RFC 2047: Message Header Extensions for Non-ASCII Text, the headers should be encoded using "B" or "Q" encoding, as handled by Encode::MIME::Header. The Subject, To and From headers should all be encoded with this module, as should any other header which may include non-ASCII characters. So the code should be:

      use Encode qw(encode); my $message = "Message with spéciâl characters"; my $msg = MIME::Lite->new( 'From' => encode('MIME-Header',$emailReturn), 'To' => encode('MIME-Header',$email), 'Subject' => encode('MIME-Header',$subject), 'Type' => 'text/html', 'Data' => $message, ); $msg->attr('Encoding' => 'quoted-printable'); $msg->attr('content-type' => 'text/html'); $msg->attr("content-type.charset" => "windows-1252"); $msg->send('smtp', "IP ADRESS", Timeout=>60);

      Clint

        I Clint, and thanks for your help but I'm still having problems with my email...

        In outlook the header is now OK but I'm receiving the source of the body as content...

        In hotmail, the content (body) is ok but the title look like something like this (éêèà âä )

        And finaly in yahoo I'm not even receiving the email...

        There a lot a documentation about the RFC but not much on the perl side about how to built email using the RFC's standart