I am currently following tutorials to try to send emails from Gmail using smtplib. I keep getting the error:
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
I am afraid that this might be something to do with Gmail updating its security to prevent people using App Passwords on Google accounts.
Any help much appreciated.
Here is the code I followed, the password was generated using the App Passwords function on Gmail:
import smtplib
from email.mime.text import MIMEText
password = "XXXXXXXXX"
subject = "Email Subject"
body = "This is the body of the text message"
sender = "[email protected]"
recipients = sender
def send_email(subject, body, sender, recipients, password):
msg = MIMEText(body)
msg["subject"] = subject
msg["From"] = sender
msg["To"] = ",".join(recipients)
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as smtp_server:
smtp_server.login(sender, password)
smtp_server.sendmail(sender, recipients,msg.as_string())
print("Message Sent!")
send_email(subject, body, sender, recipients, password)
As described, every time I try to run it, I get the error:
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Tom Osborne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.