Bug #291331 - Make send_mail() encode the unicode message as bytes before
authorZac Medico <zmedico@gentoo.org>
Wed, 4 Nov 2009 21:41:40 +0000 (21:41 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 4 Nov 2009 21:41:40 +0000 (21:41 -0000)
passing it to smtplib.SMTP.sendmail(), in order to avoid a UnicodeEncodeError
which SMTP.send() tries to encode the message a plain ascii.

svn path=/main/trunk/; revision=14776

pym/portage/mail.py

index 040cd1136955c09384c6bafbe165bc4a175417f2..9a69f9604717daf9c95768e531ef49377aad862d 100644 (file)
@@ -127,7 +127,9 @@ def send_mail(mysettings, message):
                                myconn = smtplib.SMTP(mymailhost, mymailport)
                        if mymailuser != "" and mymailpasswd != "":
                                myconn.login(mymailuser, mymailpasswd)
-                       myconn.sendmail(myfrom, myrecipient, message.as_string())
+                       msg = _unicode_encode(message.as_string(),
+                               encoding=_encodings['content'], errors='backslashreplace')
+                       myconn.sendmail(myfrom, myrecipient, msg)
                        myconn.quit()
                except smtplib.SMTPException as e:
                        raise portage.exception.PortageException(_("!!! An error occured while trying to send logmail:\n")+str(e))