0

I am try to send email in my django project using Celery and RabbitMQ. Here is my project on GitHub https://github.com/Loctarogar/Django-by-Example. In my tasks.py file typed [email protected] but i tried change it to my real google mail and that have no effects.

Every time I have this Error:

[2017-11-20 20:09:36,747: ERROR/ForkPoolWorker-4] Task orders.tasks.order_created[a8fe13ed-08dc-4971-82ff-f184e197ab8d] raised unexpected: ConnectionRefusedError(111, 'Connection refused')
Traceback (most recent call last):
  File "/home/morilon/dj/shop/lib/python3.5/site-packages/celery/app/trace.py", line 374, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/home/morilon/dj/shop/lib/python3.5/site-packages/celery/app/trace.py", line 629, in __protected_call__
    return self.run(*args, **kwargs)
  File "/home/morilon/dj/shop/myshop/orders/tasks.py", line 14, in order_created
    mail_sent = send_mail(subject, message, '[email protected]', [order.email])
  File "/home/morilon/dj/shop/lib/python3.5/site-packages/django/core/mail/__init__.py", line 62, in send_mail
    return mail.send()
  File "/home/morilon/dj/shop/lib/python3.5/site-packages/django/core/mail/message.py", line 348, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/morilon/dj/shop/lib/python3.5/site-packages/django/core/mail/backends/smtp.py", line 104, in send_messages
    new_conn_created = self.open()
  File "/home/morilon/dj/shop/lib/python3.5/site-packages/django/core/mail/backends/smtp.py", line 64, in open
    self.connection = self.connection_class(self.host, self.port, **connection_params)
  File "/usr/lib/python3.5/smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python3.5/smtplib.py", line 335, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python3.5/smtplib.py", line 306, in _get_socket
    self.source_address)
  File "/usr/lib/python3.5/socket.py", line 711, in create_connection
    raise err
  File "/usr/lib/python3.5/socket.py", line 702, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

2 Answers 2

1

I had exactly the same problem, but I solved it by setting up my settings.py just like skulegirl says, and just add this to my settings.py

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

I hope it helps you.

Sign up to request clarification or add additional context in comments.

Comments

0

Your code repo is configured to use the console backend for emails, but your backtrace is showing the smtp backend is being used. I assume you've changed the backend and that's what's causing the error.

By default, the smtp backend looks for an smtp server on localhost. I'm guessing you don't have one running there.

If you want to send via gmail's smtp servers you can do so, you just need to configure the approriate settings in your settings.py file. See the django docs for what needs to be configured. Read the gmail docs for the exact smtp host address to use.

2 Comments

Hi, may be you have some example of django project with celery? That would be very helpfull to me. For now i deal with that error , but i want to know how to sent emails to real people.
The error you were getting was completely independent of using celery. Your config in your repo looks good, just make sure to add the required smtp host info to your settings.conf file, and then you should be able to send mail regardless of whether through celery or directly from your app.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.