Sending e-mail
There are two ways to instantiate the mail sender. You can instantiate it usingthe standard method:
Or you can instantiate it passing a Scrapy settings object, which will respectthe settings:
And here is how to use it to send an e-mail (without attachments):
MailSender is the preferred class to use for sending emails from Scrapy, as ituses , like therest of the framework.
- class
scrapy.mail.
MailSender
(smtphost=None, mailfrom=None, smtpuser=None, smtppass=None, smtpport=None)[source]
Parameters:
- smtphost (str or ) – the SMTP host to use for sending the emails. If omitted, the
MAIL_HOST
setting will be used. - mailfrom () – the address used to send emails (in the
From:
header).If omitted, theMAIL_FROM
setting will be used. - smtpuser – the SMTP user. If omitted, the setting will be used. If not given, no SMTP authentication will beperformed.
- smtpport (int) – the SMTP port to connect to
- smtptls (boolean) – enforce using SMTP STARTTLS
- smtpssl (boolean) – enforce using a secure SSL connection
Parameters:settings ( object) – the e-mail recipients
send
(to, subject, body, cc=None, attachs=(), mimetype='text/plain', charset=None)- Send email to the given recipients.
Parameters:
These settings define the default init
method values of the class, and can be used to configure e-mail notifications in your project withoutwriting any code (for those extensions and code that uses MailSender
).
Default:
Sender email to use (From:
header) for sending emails.
MAIL_HOST
Default: 'localhost'
SMTP host to use for sending emails.
Default: 25
SMTP port to use for sending emails.
MAIL_USER
User to use for SMTP authentication. If disabled no SMTP authentication will beperformed.
Default: None
Password to use for SMTP authentication, along with .
MAIL_TLS
Default: False
Enforce using STARTTLS. STARTTLS is a way to take an existing insecure connection, and upgrade it to a secure connection using SSL/TLS.
Default:
Enforce connecting using an SSL encrypted connection