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?