The documentation isn't clear on whether it expects text or bytes (i.e. encoded text) for each header and for messages. The following basic code gives the warning, indicating it wants the text to be encoded for at least some of them:
#!/usr/bin/perl -w use strict; use warnings; use MIME::Lite qw( ); my $addr = '...@....com'; sub message { my ($to_name, $to_addr, $fr_name, $fr_addr, $subject, $body) = @_; my $msg = MIME::Lite->new( From => qq{"$fr_name" <$fr_addr>}, To => qq{"$to_name" <$to_addr>}, Subject => $subject, Type => 'multipart/related', ); $msg->attach( Type => 'text/plain; charset=UTF-8', Data => $body, Encoding => 'quoted-printable', ); $msg->send; } message( # Control 'a', $addr, 'a', $addr, 'a', 'a', ); message( # Test "\x{2660}", $addr, "\x{2660}", $addr, "\x{2660}", "\x{2660}", );

The documentation says it handle MIME encoding already, so all we should have to do is the character encoding.

sub message { my ($to_name, $to_addr, $fr_name, $fr_addr, $subject, $body) = @_; my $fr = qq{"$fr_name" <$fr_addr>}; my $to = qq{"$to_name" <$to_addr>}; utf8::encode( $_ ) for $to, $fr, $subject, $body; my $msg = MIME::Lite->new( From => $fr, To => $to, Subject => $subject, Type => 'multipart/related', ); $msg->attach( Type => 'text/plain; charset=UTF-8', Data => $body, Encoding => 'quoted-printable', ); $msg->send; }

The warning is gone, and the message displays fine, but looking at the raw email shows that the From, To and Subject fields aren't MIME-encoded. I guess we'll have to do that too.

sub message { my ($to_name, $to_addr, $fr_name, $fr_addr, $subject, $body) = @_; $_ = encode('MIME-Header', $_) for $to_name, $fr_name, $subject; utf8::encode( $body ); my $msg = MIME::Lite->new( From => qq{"$fr_name" <$fr_addr>}, To => qq{"$to_name" <$to_addr>}, Subject => $subject, Type => 'multipart/related', ); $msg->attach( Type => 'text/plain; charset=UTF-8', Data => $body, Encoding => 'quoted-printable', ); $msg->send; }

And bingo!


In reply to Re: MIME::Lite how to avoid wide character in subroutine for quoted/printable? by ikegami
in thread MIME::Lite how to avoid wide character in subroutine for quoted/printable? by PerlBroker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.