I want to send an e-mail with an attached CSV file. Currently, the script looks like this:

#!/usr/bin/python3 # -*- Coding: utf-8 -*- import smtplib server = smtplib.SMTP('smtp.yandex.ru', 465) server.starttls() server.login('my_login', 'my_password') msg = "YOUR MESSAGE!" server.sendmail("my@email.com", "from@email.ru", msg.as_string()) server.quit() 

So far without an attachment, just potestit the fact of sending via external SMTP. The question is: when I run the script in the console, nothing happens. No mistakes, nothing. And the invitation to enter also does not appear. Well .. that is, the script pretends that some kind of long hard work is underway. I interrupt on Ctrl + C. The letter, accordingly, does not come. The question is what happens at this moment, where and how can I catch the error?

  • To find out where it hangs, add a full traceback to the question. But it is clear that the code is not working. Start with a working code - jfs
  • @jfs copied your code by substituting your data. smtplib.SMTPServerDisconnected: Connection unexpectedly closed: timed out - Captain Flint
  • if you do not understand the error message, then ask a separate question with a minimal accurate sample code and full traceback. In the title you can write "timed out when sending e-mail". Mention your operating system, firewall settings, file size, the result of the mtr smtp.yandex.ru command (or equivalent). - jfs

1 answer 1

  Замените 465-й порт на 587. .....