Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Sending UTF-8 e-mail

by dakkar (Hermit)
on Dec 11, 2004 at 16:39 UTC ( #414118=note: print w/replies, xml ) Need Help??


in reply to Sending UTF-8 e-mail

You are almost doing it right. Your biggest problem is that MIME::Words does not work exactly as needed.

First of all, I assume you are dealing with character strings, not byte strings (read perluniintro and perlunicode for details). In that case, you should really use Encode::encode on your strings before passing them to MIME::Words::encode_mimeword.

The problem with the from and to fields (yes, they'll both get messed up) is that RFC-1522 poses some constraint on the encoding of the various parts. The easiest way to get near what the RFC requires is to use MIME::Words::encode_mimewords:

$smtp->datasend( "To: " . MIME::Words::encode_mimewords(Encode::encode +('utf-8',$self->to()), Encoding => 'Q', Charset=> 'utf-8') . "\n" );

This way I was able to send myself a message with all headers containing japanese characters.

On a sidenote: the RFC requires each encoded "word" to be less than 75 octects. Keep this in mind when encoding long subject lines.

-- 
        dakkar - Mobilis in mobile

Most of my code is tested...

Perl is strongly typed, it just has very few types (Dan)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://414118]
help
Chatterbox?
[ambrus]: Sometimes it's easier to just match elements in ways other than xpath, like directly with perl code.
[marto]: this is a cheap hack, a script that doesn't need to run for long, using WWW::Mechanize:: Firefox to drive some awful interface.
[marto]: if it were anything more serious I'd spend more time looking into it properly :P

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2016-12-08 10:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (140 votes). Check out past polls.