I am having trouble when it comes to sending emails using the send_mail method from the django.core.mail module.
The contents of the project email settings are as follows.
# --snip--
# Email Settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'mukukachilu@gmail.com'
EMAIL_HOST_PASSWORD = 'myfakepassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = False
EMAIL_USE_SSL = False
# --snip--
This is what I am doing in the Django shell.
Python 3.9.7 (default, Sep 10 2021, 14:59:43)
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.mail import send_mail
>>> from django.conf import settings
>>> send_mail('Test Subject', 'Test message', settings.EMAIL_HOST_USER, ['c.mukuka@makeitworkds.com'], fail_silently=False)
After the send_mail method hangs for a long time, I am getting this Traceback below.
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/root/djangoenv/lib/python3.9/site-packages/django/core/mail/__init__.py", line 61, in send_mail
return mail.send()
File "/root/djangoenv/lib/python3.9/site-packages/django/core/mail/message.py", line 284, in send
return self.get_connection(fail_silently).send_messages([self])
File "/root/djangoenv/lib/python3.9/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
new_conn_created = self.open()
File "/root/djangoenv/lib/python3.9/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.9/smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python3.9/smtplib.py", line 341, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.9/smtplib.py", line 312, in _get_socket
return socket.create_connection((host, port), timeout,
File "/usr/lib/python3.9/socket.py", line 844, in create_connection
raise err
File "/usr/lib/python3.9/socket.py", line 832, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out
I also did a telnet command on the Gmail smtp server like so
# telnet smtp.gmail.com 25
Trying 2a00:1450:400c:c0c::6d...
But Getting this response from telnet
telnet unable to connect to remote host: Connection timed out
I have also enabled two-factor authentication on my Gmail account and I singing in using the App password. I also tried using the method of signing in using less secure apps but it is still the same thing.
So where could I be possibly going wrong?