Maybe those API's expect you to pass them bytes and not text.
Did you try encoding your subject and your body as 'utf-8' bytes (using .encode('utf-8'))?
Simon
Le lundi 28 avril 2014 23:00:03 UTC-4, jie.l...@gmail.com a écrit :
-- Did you try encoding your subject and your body as 'utf-8' bytes (using .encode('utf-8'))?
Simon
Le lundi 28 avril 2014 23:00:03 UTC-4, jie.l...@gmail.com a écrit :
My environment is python3.3.4 django1.6.2,when I work on a django project,and I need to send email to my users through a email proxy service,but I went wrong with the django's send_mail. So I wrote a function with python's stmplib and email Lib.The code is like:def email_user(context):fromEmail = 'admin@***.cn' toEmail = ['***@qq.com'] msg = MIMEMultipart('alternative') msg.set_charset('utf8') msg['Subject'] = '欢迎注册心优雅社区,请激活您的账号' msg['From'] = fromEmail msg['To'] = ','.join(toEmail) html = """ 亲爱的%(username)s: 您好! 您在心优雅社区注册账号时使用了这个邮箱,
现在您需要点击下面的链接激活该账号: %(protocol)s://%(domain)s 如果链接无法点击,请将它完整复制到浏览器的地址栏进行访问. 链接有效期为%(expiration_days)s天, %context part = MIMEText(html,'html',_charset=失效后需重新注册. 如果您并未进行过此操作,那么可能是有人误用了您的邮箱, 请忽略此邮件.""" 'UTF-8' ) msg.attach(part) username = 'postmaster@***org' password = '****' s = smtplib.SMTP('****.com:25') s.login(username,password) s.sendmail(fromEmail,toEmail,msg .as_string()) s.quit()When I test it in the python IDLE,it work well. But,when I called this function to send email in my django project,or run it in "manage.py shell",UnicodeEncodeError let me crazy.
'ascii' codec can't encode characters in position 439-441: ordinal not in range(128) Unicode error hint The string that could not be encoded/decoded was: 亲爱的
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6d531540-1558-4c7a-a919-f50b39c3c038%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment