Answer the question
In order to leave comments, you need to log in
Why is mail not sent via python smtplib?
The code:
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
msg = MIMEMultipart()
from_email = '[email protected]'
to_email = '[email protected]'
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
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question