Я пытаюсь отправить электронное письмо через python, используя SMTP gmail, но получаю сообщение об ошибке:
Код:
import smtplib
FROM = "mail1@gmail.com"
TO = "mail2@gmail.com"
message = "Hello"
# Send the mail
server = smtplib.SMTP('smtp.gmail.com', 465)
server.ehlo()
server.starttls()
server.login('mail1@gmail.com', 'password')
server.sendmail(FROM, TO, message)
server.quit()
Ответ:
server = smtplib.SMTP('smtp.gmail.com', 465)
File "C:\Python37\lib\smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python37\lib\smtplib.py", line 338, in connect
(code, msg) = self.getreply()
File "C:\Python37\lib\smtplib.py", line 394, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed