Scrapy, a fast high-level web crawling & scraping framework for Python.
ESMTPSenderFactory takes a message of bytes
Craig Rodriguesfc406801f178
diff --git a/scrapy/mail.py b/scrapy/mail.pyindex 0bb395521..7365f25b7 100644--- a/scrapy/mail.py+++ b/scrapy/mail.py@@ -5,10 +5,10 @@ See documentation in docs/topics/email.rst"""import logging-from six.moves import cStringIO as StringIOimport sixfrom email.utils import COMMASPACE, formatdate+from io import BytesIOfrom six.moves.email_mime_multipart import MIMEMultipartfrom six.moves.email_mime_text import MIMETextfrom six.moves.email_mime_base import MIMEBase@@ -21,6 +21,14 @@ else:from twisted.internet import defer, reactor, ssl+try:+ from twisted.mail.smtp import ESMTPSenderFactory+except ImportError:+ """+ twisted.mail.smtp was not available in+ older versions of Twisted on Python 3+ """+from .utils.misc import arg_to_iterlogger = logging.getLogger(__name__)@@ -110,9 +118,7 @@ class MailSender(object):'mailattachs': nattachs, 'mailerr': errstr})def _sendmail(self, to_addrs, msg):- # Import twisted.mail here because it is not available in python3- from twisted.mail.smtp import ESMTPSenderFactory- msg = StringIO(msg)+ msg = BytesIO(msg.encode('utf-8'))d = defer.Deferred()factory = ESMTPSenderFactory(self.smtpuser, self.smtppass, self.mailfrom, \to_addrs, msg, d, heloFallback=True, requireAuthentication=False, \