Gmail SMTP Connection Fails with WinError 10060 Timeout When Attempting Email Send

I’m trying to send emails through Gmail’s SMTP server but keep running into a timeout issue. Every time I run my script, I get this error message about the connection failing. I’m wondering if this is related to recent Gmail security changes or if there’s something wrong with my setup.

import smtplib
from email.mime.text import MIMEText

def mail_sender(mail_subject, mail_content, from_address, to_address, app_password):
    message = MIMEText(mail_content)
    message['Subject'] = mail_subject
    message['From'] = from_address
    message['To'] = to_address
    
    try:
        server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
        server.login(from_address, app_password)
        server.sendmail(from_address, to_address, message.as_string())
        server.quit()
        print('Email sent successfully')
    except Exception as e:
        print(f'Error: {e}')

my_email = '[email protected]'
app_pwd = 'generated_app_password'
mail_subject = 'Test Message'
mail_content = 'Hello, this is a test email'

mail_sender(mail_subject, mail_content, my_email, my_email, app_pwd)

I generated the app password through Google’s security settings, but I’m still getting the timeout error. Has anyone else experienced this issue lately?

yeah, could be a netwrok issue. use port 587 with STARTTLS instead of that 465 port, some ISPs block it. and double check your app password, google sometimes resets those.

Had this exact issue last month - turned out my corporate firewall was blocking outbound SMTP connections. WinError 10060 timeouts usually mean network problems, not authentication issues. Try running your script on a different network first (like your phone’s hotspot) to rule out firewall interference. If it works there, contact your IT department or ISP about allowing SMTP traffic. Also check if you’ve got antivirus with email protection running - some block SMTP connections by default.