'Time out error while sending email in django

Below configs added in my settings.py, since there is no password or user name is required for this email settings, I haven't added the EMAIL_HOST_USER and EMAIL_HOST_PASSWORD

settings.py file

EMAIL_HOST = 'sample.outlook.com'
EMAIL_PORT = 25
EMAIL_USE_TLS = True
FROM_EMAIL = '[email protected]'

when I tried to execute the below comments from shell

from django.core.mail import send_mail
send_mail("test sub","test_msg","[email protected]",["[email protected]"])

getting the below error

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/ubuntu/.local/share/virtualenvs/paralel-P-lwtg7n/lib/python3.8/site-packages/django/core/mail/__init__.py", line 61, in send_mail
    return mail.send()
  File "/home/ubuntu/.local/share/virtualenvs/paralel-P-lwtg7n/lib/python3.8/site-packages/django/core/mail/message.py", line 284, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/ubuntu/.local/share/virtualenvs/paralel-P-lwtg7n/lib/python3.8/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
    new_conn_created = self.open()
  File "/home/ubuntu/.local/share/virtualenvs/paralel-P-lwtg7n/lib/python3.8/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.8/smtplib.py", line 253, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python3.8/smtplib.py", line 339, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python3.8/smtplib.py", line 308, in _get_socket
    return socket.create_connection((host, port), timeout,
  File "/usr/lib/python3.8/socket.py", line 807, in create_connection
    raise err
  File "/usr/lib/python3.8/socket.py", line 796, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out


Solution 1:[1]

Try this:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp-mail.outlook.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 25    # or 587

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1