I searched a lot but didn't find a proper solution. Seems like nobody had this problem before.
Note my socket.gaierror is [Errno 10047] which means "Address family not supported by protocol family"
The error I'm getting is when I try to integrate SMTP in my project so I can send mails.
File "C:\Users\Ubaid Parveez\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 336, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Users\Ubaid Parveez\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 307, in _get_socket
self.source_address)
File "C:\Users\Ubaid Parveez\AppData\Local\Programs\Python\Python36\lib\socket.py", line 705, in create_connection
for res in getaddrinfo(host, port, 1, SOCK_STREAM):
File "C:\Users\Ubaid Parveez\AppData\Local\Programs\Python\Python36\lib\socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 10047] getaddrinfo failed
Here's my settings for the smtp
SERVER_EMAIL = 'abc@example.com'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_PASSWORD = 'password_here'
EMAIL_HOST_USER = SERVER_EMAIL
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
Here's my view which sends the email
class ContactView(generic.TemplateView):
template_name = "contact.html"
def post(self,request,*args,**kwargs):
send_mail(
'Subject here',
'Here is the message.',
EMAIL_HOST_USER,
['to@example.com'],
fail_silently=False,
)
And when I use the send_mail() function in my view. I get this socket error. This error goes away if I change my email backend to "django.core.mail.backends.console.EmailBackend".