Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

removed (somewhat hacky) MAIL_DEBUG setting

Pablo Hoffman6585c1a28f6f
diff --git a/docs/topics/email.rst b/docs/topics/email.rst
index c2dd0a450..9c01c9c8d 100644
--- a/docs/topics/email.rst
+++ b/docs/topics/email.rst
@@ -58,9 +58,6 @@ uses `Twisted non-blocking IO`_, like the rest of the framework.
Send email to the given recipients. Emits the :signal:`mail_sent` signal.
- If :setting:`MAIL_DEBUG` is enabled the :signal:`mail_sent` signal will
- be emmited and no actual email will be sent.
-
:param to: the e-mail recipients
:type to: list
@@ -136,15 +133,6 @@ Default: ``None``
Password to use for SMTP authentication, along with :setting:`MAIL_USER`.
-.. setting:: MAIL_DEBUG
-
-MAIL_DEBUG
-----------
-
-Default: ``False``
-
-Whether to enable the debugging mode.
-
Mail signals
============
diff --git a/scrapy/mail.py b/scrapy/mail.py
index 17973e584..a7e4c94f7 100644
--- a/scrapy/mail.py
+++ b/scrapy/mail.py
@@ -28,12 +28,13 @@ mail_sent = object()
class MailSender(object):
def __init__(self, smtphost=None, mailfrom=None, smtpuser=None, smtppass=None, \
- smtpport=None):
+ smtpport=None, debug=False):
self.smtphost = smtphost or settings['MAIL_HOST']
self.smtpport = smtpport or settings.getint('MAIL_PORT')
self.smtpuser = smtpuser or settings['MAIL_USER']
self.smtppass = smtppass or settings['MAIL_PASS']
self.mailfrom = mailfrom or settings['MAIL_FROM']
+ self.debug = debug
if not self.smtphost or not self.mailfrom:
raise NotConfigured("MAIL_HOST and MAIL_FROM settings are required")
@@ -67,7 +68,7 @@ class MailSender(object):
send_catch_log(signal=mail_sent, to=to, subject=subject, body=body,
cc=cc, attach=attachs, msg=msg)
- if settings.getbool('MAIL_DEBUG'):
+ if self.debug:
log.msg('Debug mail sent OK: To=%s Cc=%s Subject="%s" Attachs=%d' % \
(to, cc, subject, len(attachs)), level=log.DEBUG)
return
diff --git a/scrapy/tests/test_mail.py b/scrapy/tests/test_mail.py
index efc93abb5..4512997f8 100644
--- a/scrapy/tests/test_mail.py
+++ b/scrapy/tests/test_mail.py
@@ -3,22 +3,20 @@ import unittest
from scrapy.xlib.pydispatch import dispatcher
-from scrapy.conf import settings
from scrapy.mail import MailSender, mail_sent
class MailSenderTest(unittest.TestCase):
def setUp(self):
- settings.disabled = False
- settings.overrides['MAIL_DEBUG'] = True
-
self.catched_msg = None
-
dispatcher.connect(self._catch_mail_sent, signal=mail_sent)
+ def tearDown(self):
+ dispatcher.disconnect(self._catch_mail_sent, signal=mail_sent)
+
def test_send(self):
- mailsender = MailSender()
+ mailsender = MailSender(debug=True)
mailsender.send(to=['[email protected]'], subject='subject', body='body')
assert self.catched_msg
@@ -38,7 +36,7 @@ class MailSenderTest(unittest.TestCase):
attach.seek(0)
attachs = [('attachment', 'text/plain', attach)]
- mailsender = MailSender()
+ mailsender = MailSender(debug=True)
mailsender.send(to=['[email protected]'], subject='subject', body='body',
attachs=attachs)
@@ -59,10 +57,6 @@ class MailSenderTest(unittest.TestCase):
self.assertEqual(text.get_payload(decode=True), 'body')
self.assertEqual(attach.get_payload(decode=True), 'content')
- def tearDown(self):
- del settings.overrides['MAIL_DEBUG']
- settings.disabled = True
-
def _catch_mail_sent(self, **kwargs):
self.catched_msg = dict(**kwargs)