Perl Mail::Sendmail encoding problem
--0016363b8df28ae827049a14a977
Content-Type: text/plain; charset=ISO-8859-1
Greetings all,
I have to send emails through a smtp server, with Chinese character
encoding.
In details , the encoding of my send mail is UTF-8, but the encoding of
others received is GB2321 , so it will apprears with "weird" characters.
Does anyone has any working example or any suggestion please ?
Best Regards,
My code is :
1. #!/usr/bin/perl
2.
3.
4. use strict;
5. use Mail::Sendmail;
6. use MIME::Base64;
7.
8. my $content = `cat tmp.txt`;
9.
10. print "Sending an email .....";
11.
12. my %mail = (
13. To => "xx [at] xx.com",
14. From => "xx [at] xx.com",
15. Subject => "test",
16. content-type => "text/plain",
17. content-transfer-encoding => 'base64',
18. Message => $content,
19. smtp => "xx.xx.xx",
20. );
21.
22.
23. if (sendmail %mail) { print "Mail send ok!\n";}
24.
25. else {print "Error : $mail::Sendmail::errror\n"}
The "tmp.txt" is the content of Chinese .
--0016363b8df28ae827049a14a977--
Re: Perl Mail::Sendmail encoding problem
Hi sync,
On Tuesday 18 Jan 2011 03:17:21 sync wrote:
> Greetings all,
>
> I have to send emails through a smtp server, with Chinese character
> encoding.
>
>
> In details , the encoding of my send mail is UTF-8, but the encoding of
>
> others received is GB2321 , so it will apprears with "weird" characters.
>
>
> Does anyone has any working example or any suggestion please ?
>
Maybe look into the Encode module and maybe try
http://search.cpan.org/dist/Email-Sender/ instead of Mail-Sendmail.
Now a few comments on your code:
> Best Regards,
>
>
> My code is :
>
> 1. #!/usr/bin/perl
> 2.
> 3.
> 4. use strict;
Also add "use warnings;".
> 5. use Mail::Sendmail;
> 6. use MIME::Base64;
> 7.
> 8. my $content = `cat tmp.txt`;
> 9.
Don't slurp files this way:
http://perl-begin.org/tutorials/bad-elements/#slurp
> 10. print "Sending an email .....";
> 11.
Don't you want a \n here?
> 12. my %mail = (
> 13. To => "xx [at] xx.com",
> 14. From => "xx [at] xx.com",
> 15. Subject => "test",
> 16. content-type => "text/plain",
> 17. content-transfer-encoding => 'base64',
> 18. Message => $content,
> 19. smtp => "xx.xx.xx",
These are not aligned properly.
> 20. );
> 21.
> 22.
> 23. if (sendmail %mail) { print "Mail send ok!\n";}
> 24.
Please Indent properly.
> 25. else {print "Error : $mail::Sendmail::errror\n"}
>
It should be: "$Mail::Sendmail::error" - you have a lowercase "m" and three
consecutive "r"'s instead of two.
http://search.cpan.org/~mivkovic/Mail-
Sendmail-0.79/Sendmail.pm#$Mail::Sendmail::error
>
> The "tmp.txt" is the content of Chinese .
Regards,
Shlomi Fish
--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
Funny Anti-Terrorism Story - http://shlom.in/enemy
Chuck Norris can make the statement "This statement is false" a true one.
Please reply to list if it's a mailing list post - http://shlom.in/reply .
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Perl Mail::Sendmail encoding problem
>>>>> "SF" == Shlomi Fish <shlomif [at] iglu.org.il> writes:
SF> Don't slurp files this way:
SF> http://perl-begin.org/tutorials/bad-elements/#slurp
if you are going to show a slurp sub in your tutorial at least show a
good one. look at my slurp article in the File::Slurp distro for a
better and faster one. avoiding perl's i/o is key to speed. and i don't
mean using File::Slurp itself which you mention.
uri
--
Uri Guttman ------ uri [at] stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/