|
|
Scrapy sends e-mails using its own facility called as Twisted non-blocking IO which keeps away from non-blocking IO of the crawler. Few settings of sending emails can be configured and you can provide simple API to send attachments.
There are two ways to instantiate the MailSender as shown in below table
Sr.No |
Parameters |
Method |
1 |
from scrapy.mail import MailSender mailer = MailSender() |
By using a standard constructor. |
2 |
mailer = MailSender.from_settings(settings) |
By using Scrapy settings object. |
Below line sends an e-mail without attachments
MailSender class makes use of Twisted non-blocking IO for sending e-mails from Scrapy.
Below table displays the parameters used in MailSender class
Sr.No |
Parameter & Description |
1 |
smtphost (str) SMTP host is used to send emails. Else MAIL_HOST setting can be used. |
2 |
mailfrom (str) Address of receiver can be used to send emails. Else MAIL_FROM setting can be used. |
3 |
smtpuser It will specify the SMTP user. Else MAIL_USER setting can be used and there will be no SMTP validation if is not mentioned. |
4 |
smtppass (str) It will specify the SMTP pass for validation. |
5 |
smtpport (int) It will specify the SMTP port for connection. |
6 |
smtptls (boolean) It will implement using the SMTP STARTTLS. |
7 |
smtpssl (boolean) It will administer using a safe SSL connection. |
Below two methods are there in MailSender class reference as specified. First method,
It can be incorporated using Scrapy settings object. It consists of below parameter
settings (scrapy.settings.Settings object) − It is treated as e-mail receiver.
Another method,
Below table contains the parameters of the above method
Sr.No |
Parameter & Description |
1 |
to (list) It will refer to the email receiver. |
2 |
subject (str) It will specify the subject of the email. |
3 |
cc (list) It will refer to the list of receivers. |
4 |
body (str) It will refer to the email body data. |
5 |
attachs (iterable) It will refer to the email's attachment, mimetype of the attachment and name of the attachment. |
6 |
mimetype (str) It represents the MIME type of the e-mail. |
7 |
charset (str) It will specify the character encoding used for email contents. |
Below settings ensure that without writing any code, you can configure an e-mail using MailSender class in the project.
Sr.No |
Settings & Description |
Default Value |
1 |
MAIL_FROM It will refer to sender email for sending emails. |
'scrapy@localhost' |
2 |
MAIL_HOST It will refer to SMTP host used for sending emails. |
'localhost' |
3 |
MAIL_PORT It will specify SMTP port to be used for sending emails. |
25 |
4 |
MAIL_USER It will refer to SMTP validation. There will be no validation, if this setting is set to disable. |
None |
5 |
MAIL_PASS It will provide the password used for SMTP validation. |
None |
6 |
MAIL_TLS It will provide the method of upgrading an insecure connection to a secure connection using SSL/TLS. |
False |
7 |
MAIL_SSL It will implement the connection using a SSL encrypted connection. |
False |
|
|
Scrapy Related Tutorials |
|
---|---|
Python Tutorial | Zend Tutorial |
Django Tutorial | Framework7 Tutorial |
wxPython Tutorial | Windows 10 Tutorial |
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.