Hi, I'm trying a simple code sending email from my web app as below:
from django.core.mail import send_mail
from django.conf import settings
settings.configure()
send_mail(
'Subject here',
'Here is the message.',
'info@mydomain.com',
['to@gmail.com'],
fail_silently=False
)
and in my settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'info@mydomain.com'
EMAIL_HOST_PASSWORD = 'xxxxxxxxxxx'
EMAIL_USE_TLS = True
email domain is google domain, as well email account is Gmail account. I'm using generated app password, enabled captcha for my email account also allowed less secure apps to connect.
But, I'm getting below error.
Traceback (most recent call last):
File "calc.py", line 11, in <module>
fail_silently=False
File "/home/mohamed0youssef/.virtualenvs/myrede/lib/python3.7/site-packages/django/core/mail/__init__.py", line 60, in send_mail
return mail.send()
File "/home/mohamed0youssef/.virtualenvs/myrede/lib/python3.7/site-packages/django/core/mail/message.py", line 276, in send
return self.get_connection(fail_silently).send_messages([self])
File "/home/mohamed0youssef/.virtualenvs/myrede/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
new_conn_created = self.open()
File "/home/mohamed0youssef/.virtualenvs/myrede/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 62, in open
self.connection = self.connection_class(self.host, self.port, **connection_params)
File "/usr/lib/python3.7/smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python3.7/smtplib.py", line 336, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.7/smtplib.py", line 307, in _get_socket
self.source_address)
File "/usr/lib/python3.7/socket.py", line 727, in create_connection
raise err
File "/usr/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused