I am using Django to send e-mails. I am getting a common network error apparently, but not any of the answers I've read solved. I have a problem with the socket I believe,
When I send the e-mail I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Jaime\Miniconda3\envs\mydjango\lib\site-
packages\django\core\mail\message.py", line 291, in send
return self.get_connection(fail_silently).send_messages([self])
File "C:\Users\Jaime\Miniconda3\envs\mydjango\lib\site-
packages\django\core\mail\backends\smtp.py", line 103, in send_messages
new_conn_created = self.open()
File "C:\Users\Jaime\Miniconda3\envs\mydjango\lib\site-
packages\django\core\mail\backends\smtp.py", line 63, in open
self.connection = self.connection_class(self.host, self.port,
**connection_params)
File "C:\Users\Jaime\Miniconda3\envs\mydjango\lib\smtplib.py", line 251,
in __init__
(code, msg) = self.connect(host, port)
File "C:\Users\Jaime\Miniconda3\envs\mydjango\lib\smtplib.py", line 336,
in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Users\Jaime\Miniconda3\envs\mydjango\lib\smtplib.py", line 307,
in _get_socket
self.source_address)
File "C:\Users\Jaime\Miniconda3\envs\mydjango\lib\socket.py", line 727,
in create_connection
raise err
File "C:\Users\Jaime\Miniconda3\envs\mydjango\lib\socket.py", line 716,
in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made
because
the target machine actively refused it
Here is what I've tried:
1. import socket socket.getaddrinfo('hotmail-com.olc.protection.outlook.com', 80) socket.getaddrinfo('smtp.hotmail.com', 8000) socket.getaddrinfo('smtp.hotmail.com', 587)
- Turn off Firewall / Antivirus
- Run the code in python shell and in Django app
- I've got the smtp server out of a nslookup MX query
I am running this test code in the python shell:
from django.conf import settings
from django.core.mail import EmailMessage
settings.configure()
from django.core.mail import send_mail
import socket
socket.getaddrinfo('hotmail-com.olc.protection.outlook.com', 80)
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'hotmail-com.olc.protection.outlook.com'
EMAIL_HOST_USER = '*******@hotmail.com'
EMAIL_HOST_PASSWORD = '******'
EMAIL_PORT = 587
mail_subject = 'Activate your blog account.'
to_email = "******@hotmail"
email = EmailMessage(
mail_subject, "hello", to=[to_email]
)
email.send()
Expected Result:
For now I want to send e-mails from localhost Django app. In the future I will upload the code to pythonanywhere.com server.