Message100380
The as_string method in mime classes in module email.mime use base64 to encode the text, but segmentedly while the text contents non-acsii characters and is in type of unicode. This behavior confuse some of the email servers.
For example:
===================================================================
#-*- coding: utf-8 -*-
import base64
from email.mime.text import MIMEText
content = u'''Hello:
这是一封测试邮件.
Please remove this message after reading,
and I hope this won't bother you for a long time
'''
m = MIMEText(content, 'plain', 'utf-8')
print m.as_string()
m = MIMEText(content.encode('utf-8'), 'plain', 'utf-8')
print m.as_string()
print base64.encodestring(content.encode('utf-8'))
===================================================================
The first as_string method gives:
-------------------------------------------------------------------
SGVsbG86CiAgICDov5nmmK/kuIDlsIHmtYvor5Xpgq7ku7YuCiAgIFBsZWFzZSByZW1vdmUgdGhpcyBtZXNzYWdlIGFmdGVyIA==
cmVhZGluZywKICAgYW5kIEkgaG9wZSB0aGlzIHdvbid0IGJvdGhlciB5b3UgZm9yIGEgbG9uZyB0
aW1lCg==
-------------------------------------------------------------------
Please notice that there is a '==' at the end of the first line.
The output of both the second as_string and base64.encodestring method maybe more appropriate, which is:
-------------------------------------------------------------------
SGVsbG86CiAgICDov5nmmK/kuIDlsIHmtYvor5Xpgq7ku7YuCiAgIFBsZWFzZSByZW1vdmUgdGhp
cyBtZXNzYWdlIGFmdGVyIHJlYWRpbmcsCiAgIGFuZCBJIGhvcGUgdGhpcyB3b24ndCBib3RoZXIg
eW91IGZvciBhIGxvbmcgdGltZQo= |
|
Date |
User |
Action |
Args |
2010-03-04 08:24:55 | dongying | set | recipients:
+ dongying |
2010-03-04 08:24:55 | dongying | set | messageid: <1267691095.13.0.237646934918.issue8054@psf.upfronthosting.co.za> |
2010-03-04 08:24:53 | dongying | link | issue8054 messages |
2010-03-04 08:24:53 | dongying | create | |
|