I'm trying to send an email with python, however when i try running my code, it keeps telling me 'socket.gaierror: [Errno -3] Temporary failure in name resolution'. This is my first time of trying to send email with python, so i really can't tell where the fault might be coming from. My Code;
import os
from email.message import EmailMessage
import ssl
import smtplib
email_sender = 'emailtesting437@gmail.com'
email_password = os.environ.get('PYTHON_PASS')
email_receiever = 'victorycollins31@gmail.com'
subject = 'testing the email'
body = """"
i have just publisshed a new video pls check out
"""
em = EmailMessage()
em['from'] = email_sender
em['to'] = email_receiever
em['subject'] = subject
em.set_content(body)
context = ssl.create_default_context()
with smtplib.SMTP_SSL('smtp.gmail.com', 465, context=context) as smtp:
smtp.login(email_sender, email_password)
smtp.sendmail(email_sender, email_receiever, em.as_string())
Error:
/home/lenovo/PycharmProjects/pythonProject/venv/bin/python /home/lenovo/PycharmProjects/pythonProject/exceptn_modules.py
Traceback (most recent call last):
File "/home/lenovo/PycharmProjects/pythonProject/exceptn_modules.py", line 23, in <module>
with smtplib.SMTP_SSL('smtp.gmail.com', 465, context=context) as smtp:
File "/usr/lib/python3.8/smtplib.py", line 1043, in __init__
SMTP.__init__(self, host, port, local_hostname, timeout,
File "/usr/lib/python3.8/smtplib.py", line 255, 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 1049, in _get_socket
new_socket = socket.create_connection((host, port), timeout,
File "/usr/lib/python3.8/socket.py", line 787, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution