Я пытаюсь отправить электронное письмо с python. Все отлично работает, кроме отправляющей части. Вот мой код плюс вывод. Как видите, все работает хорошо до функции sendmail
.
import smtplib
from email.mime.text import MIMEText
Subject = "Test"
Body = "TestingTheBesting"
Message = f"{Subject}\n\n{Body}"
msg = MIMEText(Message)
msg['From'] = "leovandenbrandt@gmx.net"
msg['To'] = ["leovandenbrandt@gmx.net"]
with smtplib.SMTP('smtp.gmx.com', 587) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.esmtp_features['auth'] = 'LOGIN DIGEST-MD5 PLAIN'
smtp.login("leovandenbrandt@gmx.net", ".......")
print("d")
smtp.sendmail(msg['From'], msg['To'], msg)
print("i")
smtp.close()``
d
Traceback (most recent call last):
File "mailtest.py", line 22, in <module>
smtp.sendmail(msg['From'], msg['To'], msg)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/smtplib.py", line 886, in sendmail
(code, resp) = self.data(msg)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/smtplib.py", line 568, in data
q = _quote_periods(msg)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/smtplib.py", line 176, in _quote_periods
return re.sub(br'(?m)^\.', b'..', bindata)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/re.py", line 208, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "mailtest.py", line 24, in <module>
smtp.close()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/smtplib.py", line 282, in __exit__
raise SMTPResponseException(code, message)
smtplib.SMTPResponseException: (421, b'gmx.com Service closing transmission channel - command timeout')