Django Error Errno 11001 getaddrinfo failed

Trying to send email using smtp on gmail but getting 'error 11001 getaddrinfo failed'. I am not sure what I'm doing wrong.

Here is my 'settings.py'

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_SSL = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '******@gmail.com' 
EMAIL_HOST_PASSWORD = '********'
EMAIL_PORT = 465 

mail function:

def send_notification(dataframe):
    subject = 'That’s your subject'
    from_email = settings.EMAIL_HOST_USER 
    to = '*******@gmail.com'
    text_content = 'That’s your plain text.'
    html_content = """\
            <html>
              <head></head>
              <body>
                <p> Test email from django </p>
              </body>
            </html>
        """
    message = EmailMultiAlternatives(subject, text_content, from_email, [to])
    message.attach_alternative(html_content, "text/html")
    message.send()

Error:

for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
[26/Jul/2022 13:21:51] "GET / HTTP/1.1" 500 114527
Back to Top