mirror of https://github.com/scrapy/scrapy.git
Encode message using supplied charset
This commit is contained in:
parent
fc406801f1
commit
12c7628fcb
|
|
@ -5,10 +5,13 @@ See documentation in docs/topics/email.rst
|
|||
"""
|
||||
import logging
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO as BytesIO
|
||||
except ImportError:
|
||||
from io import BytesIO
|
||||
import six
|
||||
|
||||
from email.utils import COMMASPACE, formatdate
|
||||
from io import BytesIO
|
||||
from six.moves.email_mime_multipart import MIMEMultipart
|
||||
from six.moves.email_mime_text import MIMEText
|
||||
from six.moves.email_mime_base import MIMEBase
|
||||
|
|
@ -21,14 +24,6 @@ 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_iter
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -96,7 +91,7 @@ class MailSender(object):
|
|||
'mailattachs': len(attachs)})
|
||||
return
|
||||
|
||||
dfd = self._sendmail(rcpts, msg.as_string())
|
||||
dfd = self._sendmail(rcpts, msg.as_string().encode(charset or 'utf-8'))
|
||||
dfd.addCallbacks(self._sent_ok, self._sent_failed,
|
||||
callbackArgs=[to, cc, subject, len(attachs)],
|
||||
errbackArgs=[to, cc, subject, len(attachs)])
|
||||
|
|
@ -118,7 +113,9 @@ class MailSender(object):
|
|||
'mailattachs': nattachs, 'mailerr': errstr})
|
||||
|
||||
def _sendmail(self, to_addrs, msg):
|
||||
msg = BytesIO(msg.encode('utf-8'))
|
||||
# Import twisted.mail here because it is not available in python3
|
||||
from twisted.mail.smtp import ESMTPSenderFactory
|
||||
msg = BytesIO(msg)
|
||||
d = defer.Deferred()
|
||||
factory = ESMTPSenderFactory(self.smtpuser, self.smtppass, self.mailfrom, \
|
||||
to_addrs, msg, d, heloFallback=True, requireAuthentication=False, \
|
||||
|
|
|
|||
Loading…
Reference in New Issue