2009-08-18 14:05:15 -03:00
|
|
|
.. _topics-email:
|
2009-01-11 19:11:17 +00:00
|
|
|
|
2010-04-18 23:42:56 -03:00
|
|
|
==============
|
2010-04-18 23:39:54 -03:00
|
|
|
Sending e-mail
|
2010-04-18 23:42:56 -03:00
|
|
|
==============
|
2009-01-11 19:11:17 +00:00
|
|
|
|
|
|
|
.. module:: scrapy.mail
|
2010-04-18 23:39:54 -03:00
|
|
|
:synopsis: Email sending facility
|
2009-01-11 19:11:17 +00:00
|
|
|
|
2010-04-18 23:39:54 -03:00
|
|
|
Although Python makes sending e-mails relatively easy via the `smtplib`_
|
|
|
|
library, Scrapy provides its own facility for sending e-mails which is very easy
|
|
|
|
to use and it's implemented using `Twisted non-blocking IO`_, to avoid
|
|
|
|
interfering with the non-blocking IO of the crawler.
|
|
|
|
|
|
|
|
It's also very easy to configure, having only a few settings.
|
2009-01-11 19:11:17 +00:00
|
|
|
|
2009-01-11 23:04:50 +00:00
|
|
|
.. _smtplib: http://docs.python.org/library/smtplib.html
|
2010-04-18 23:39:54 -03:00
|
|
|
.. _Twisted non-blocking IO: http://twistedmatrix.com/projects/core/documentation/howto/async.html
|
2009-01-11 19:11:17 +00:00
|
|
|
|
2009-01-11 23:04:50 +00:00
|
|
|
It also has built-in support for sending attachments.
|
2009-01-11 19:11:17 +00:00
|
|
|
|
|
|
|
Quick example
|
|
|
|
=============
|
|
|
|
|
2010-04-18 23:39:54 -03:00
|
|
|
Here's a quick example of how to send an e-mail (without attachments)::
|
2009-01-11 19:11:17 +00:00
|
|
|
|
|
|
|
from scrapy.mail import MailSender
|
|
|
|
|
|
|
|
mailer = MailSender()
|
2009-03-10 19:56:22 +00:00
|
|
|
mailer.send(to=["someone@example.com"], subject="Some subject", body="Some body", cc=["another@example.com"])
|
2009-01-11 19:11:17 +00:00
|
|
|
|
2009-01-11 23:04:50 +00:00
|
|
|
MailSender class reference
|
|
|
|
==========================
|
2009-01-11 19:11:17 +00:00
|
|
|
|
2009-01-11 23:04:50 +00:00
|
|
|
MailSender is the preferred class to use for sending emails from Scrapy, as it
|
|
|
|
uses `Twisted non-blocking IO`_, like the rest of the framework.
|
2009-01-11 19:49:11 +00:00
|
|
|
|
2009-01-19 00:35:28 +00:00
|
|
|
.. class:: MailSender(smtphost, mailfrom)
|
2009-01-11 19:11:17 +00:00
|
|
|
|
2010-04-18 23:39:54 -03:00
|
|
|
:param smtphost: the SMTP host to use for sending the emails. If omitted, the
|
|
|
|
:setting:`MAIL_HOST` setting will be used.
|
|
|
|
:type smtphost: str
|
2009-01-11 19:11:17 +00:00
|
|
|
|
2010-04-18 23:39:54 -03:00
|
|
|
:param mailfrom: the address used to send emails (in the ``From:`` header).
|
|
|
|
If omitted, the :setting:`MAIL_FROM` setting will be used.
|
|
|
|
:type mailfrom: str
|
2009-01-11 19:11:17 +00:00
|
|
|
|
2010-04-18 23:39:54 -03:00
|
|
|
.. method:: send(to, subject, body, cc=None, attachs=())
|
2009-01-11 19:11:17 +00:00
|
|
|
|
2010-04-18 23:39:54 -03:00
|
|
|
Send email to the given recipients
|
2009-01-19 00:35:28 +00:00
|
|
|
|
2010-04-18 23:39:54 -03:00
|
|
|
:param to: the e-mail recipients
|
|
|
|
:type to: list
|
2009-01-11 19:11:17 +00:00
|
|
|
|
2010-04-18 23:39:54 -03:00
|
|
|
:param subject: the subject of the e-mail
|
|
|
|
:type subject: str
|
2009-01-11 19:11:17 +00:00
|
|
|
|
2010-04-18 23:39:54 -03:00
|
|
|
:param cc: the e-mails to CC
|
|
|
|
:type cc: list
|
2009-01-11 19:11:17 +00:00
|
|
|
|
2010-04-18 23:39:54 -03:00
|
|
|
:param body: the e-mail body
|
|
|
|
:type body: str
|
2009-01-11 19:11:17 +00:00
|
|
|
|
2010-04-18 23:39:54 -03:00
|
|
|
:param attachs: an iterable of tuples ``(attach_name, mimetype,
|
|
|
|
file_object)`` where ``attach_name`` is a string with the name that will
|
|
|
|
appear on the e-mail's attachment, ``mimetype`` is the mimetype of the
|
|
|
|
attachment and ``file_object`` is a readable file object with the
|
|
|
|
contents of the attachment
|
|
|
|
:type attachs: iterable
|
2009-01-13 11:55:20 +00:00
|
|
|
|
2009-01-11 19:11:17 +00:00
|
|
|
|
2010-04-18 23:39:54 -03:00
|
|
|
MailSender settings
|
|
|
|
===================
|
|
|
|
|
|
|
|
These settings define the default constructor values of the :class:`MailSender`
|
|
|
|
class, and can be used to configure e-mail notifications in your project without
|
|
|
|
writing any code (for those extensions that use the :class:`MailSender` class):
|
|
|
|
|
|
|
|
* :setting:`MAIL_FROM`
|
|
|
|
* :setting:`MAIL_HOST`
|
2009-01-11 23:04:50 +00:00
|
|
|
|