Reputation: 1031
I am new to Python and Scrapy.
All I want to achieve, is send a simple email, using only Scrapy. I have read the documentation from the creators' webpage and I must be missing something, but I can't quite put my finger on it.
Here is the code:
from scrapy import mail
mailer = mail.MailSender(smtphost='smtp-mail.outlook.com',
mailfrom='[email protected]',
smtpuser='[email protected]',
smtppass='mypassword',
smtpport=587,
smtptls=True,
)
def send_mail(mail_sender):
return mail_sender.send(to=["[email protected]"],
subject="Hello",
body="Hello receiver",
mimetype='text/plain')
send_mail(mailer)
Update: I am running this script with pycharm instead of using scrapy.cmdline
. Does this have anything to do as to why my code is not working?
This is the output I get:
Process finished with exit code 0
Upvotes: 1
Views: 149
Reputation: 1031
The problem was that I was running the script directly from my IDE (Pycharm).
To run a spider from the IDE, without using a terminal, one could invoke a command programmatically.
Scrapy has a module that allows doing this:
from scrapy import cmdline
cmdline.execute("scrapy crawl <spider_name>".split())
Scrapy email library works like a charm!
Upvotes: 1