Код:
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
msg = MIMEMultipart()
from_email = 'MyEmail@yandex.com'
to_email = 'RecipientEmail@gmail.ru'
login = 'MyLogin'
password = 'MyPassWord'
message = 'Test Message'
msg.attach(MIMEText(message, 'plain'))
server = smtplib.SMTP('smtp.yandex.ru', 465)
server.starttls()
server.login(login, password)
server.sendmail(from_email, to_email, msg.as_string())
server.quit()
Ошибка:
Traceback (most recent call last):
File "C:\Users\krlls\Desktop\letter.py", line 17, in <module>
server = smtplib.SMTP('smtp.yandex.ru', 465)
File "C:\Users\krlls\AppData\Local\Programs\Python\Python39\lib\smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
File "C:\Users\krlls\AppData\Local\Programs\Python\Python39\lib\smtplib.py", line 343, in connect
(code, msg) = self.getreply()
File "C:\Users\krlls\AppData\Local\Programs\Python\Python39\lib\smtplib.py", line 400, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed