#!/usr/bin/perl -w # For correct results, use on a terminal expecting utf-8 use strict; use Email::MIME; sub new_part ($$) { my ($type, $body) = @_; my ($part) = Email::MIME->create( attributes => { content_type => $type, charset => 'utf-8', encoding => '8bit', }, body_str => $body, ); do { $part->header_set($_) } foreach qw/Date MIME-Version/; return $part; } # Normally, this would be actual utf-8 under "use utf8" my $text = "Not latin: \x{30ab}\x{30bf}\x{30ab}\x{30ca}"; my $html = "

$text

"; my $m = Email::MIME->create(header_str => [ To => 'a@example.com', From => 'b@example.com', Subject => 'Test', ], attributes => { content_type => 'multipart/alternative', }, parts => [ new_part('text/html', $html), new_part('text/plain', $text) ]); print $m->as_string; #### #!/usr/bin/perl -W # vim:fileencoding=utf-8 # PuTTY option: Remote character set = UTF-8 # my locale: en_US.UTF-8 (LANG and all LC_* except LC_ALL="") use warnings; use strict; use utf8; use MIME::Lite; use MIME::Base64; my $m = MIME::Lite->new(To => 'a@example.com', From => 'b@example.net', Subject => 'Test', Type => 'TEXT', # Perlmonks safe encoding with same result Data => "Not latin: \x{30ab}\x{30bf}\x{30ab}\x{30ca}\n"); my $s = $m->as_string; print "UTF-8 flag: ", utf8::is_utf8($s), "\n"; binmode(STDOUT, ':raw'); print $s; # warns: wide char in print print encode_base64($s); # dies: wide char in sub entry