Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting this error: "TimeoutError: [Errno 110] Connection timed out" using python code in Pycharm?

Tags:

python

import smtplib

my_email = "*******@gmail.com"
password = "***********"

with smtplib.SMTP("smtp.gmail.com") as connection:
    connection.starttls()
    connection.login(user=my_email, password=password)
    connection.sendmail(from_addr=my_email, to_addrs="*******@yahoo.com",
                        msg="Subject:Hello\n\n This is the body of my email.")

In gmail the "less secure apps" feature was enabled. Conversely, in Yahoo, the "Generate App Password" feature was used and still got the same response for both instances.

like image 354
Les Avatar asked May 14 '26 17:05

Les


1 Answers

There can be many reasons for this error - typically it means something has gone wrong in setting up the smtplib connection and your email hasn't set.

To get a more descriptive and helpful error message, you need to enable debugging.

To do that add, add this line of code:

connection.set_debuglevel(1)

That will print out much more descriptive debugger messages to the console.

like image 153
osint_alex Avatar answered May 17 '26 06:05

osint_alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!