PacktPublishing / Django-4-by-example

Django 4 by example (4th Edition) published by Packt
https://djangobyexample.com/
MIT License
799 stars 461 forks source link

Chapter 8: Sending emails using gmail smtp #26

Closed gavin-dev21 closed 1 year ago

gavin-dev21 commented 1 year ago

Hello,

I have been trying to send emails using gmail smtp with celery and rabbitmq. Currently, I am receiving the following error in my celery shell:

[2022-12-03 22:22:57,022: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672// [2022-12-03 22:22:57,040: INFO/MainProcess] mingle: searching for neighbors [2022-12-03 22:22:57,055: WARNING/MainProcess] No hostname was supplied. Reverting to default 'localhost' [2022-12-03 22:22:57,419: INFO/SpawnPoolWorker-1] child process 26596 calling self.run() ...

and then down the console:

[2022-12-03 22:23:31,615: INFO/MainProcess] Task orders.tasks.order_created[386624de-daa4-41e2-b3ed-ada61d24af0e] received [2022-12-03 22:23:32,430: INFO/SpawnPoolWorker-17] child process 5664 calling self.run() [2022-12-03 22:23:32,431: INFO/SpawnPoolWorker-18] child process 5072 calling self.run() [2022-12-03 22:23:32,434: INFO/SpawnPoolWorker-20] child process 4692 calling self.run() [2022-12-03 22:23:32,434: INFO/SpawnPoolWorker-19] child process 3700 calling self.run() [2022-12-03 22:23:32,436: INFO/SpawnPoolWorker-21] child process 24296 calling self.run() [2022-12-03 22:23:32,441: INFO/SpawnPoolWorker-22] child process 7460 calling self.run() [2022-12-03 22:23:32,441: INFO/SpawnPoolWorker-23] child process 16564 calling self.run() [2022-12-03 22:23:32,444: INFO/SpawnPoolWorker-24] child process 12252 calling self.run() [2022-12-03 22:23:34,011: INFO/SpawnPoolWorker-25] child process 13780 calling self.run()

But it never reaches success.

I have all of the files the way you have it in the book. However, I'm wondering if I may need some extra specifications for the settings.py file.

For example I currently have:

EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 EMAIL_USE_TLS = True

As well as the appropriate gmail app password for EMAIL_HOST_PASSWORD and my email as EMAIL_HOST_USER.

Any help you could provide would be appreciated.

gavin-dev21 commented 1 year ago

Hello I got it to work. The answer was provide in this link:

https://stackoverflow.com/questions/62524908/task-receive-but-doesnt-excute

Apparently Celery >4.x no longer supports Windows. To solve this, do the following:

pip install gevent

Then ->

celery -A myshop worker -l info -P gevent

and it will work.

zenx commented 1 year ago

@gavin-dev21 thank you for providing the solution for this Windows issue.