SMTPServerDisconnected can also happen when creating SMTP server object

This commit is contained in:
Son NK 2020-12-31 11:22:45 +01:00
parent 0b83835065
commit 1c22e14f68

View file

@ -1667,15 +1667,15 @@ def sl_sendmail(
from_addr, to_addr, msg: Message, mail_options, rcpt_options, can_retry=True
):
"""replace smtp.sendmail"""
if POSTFIX_SUBMISSION_TLS:
smtp = SMTP(POSTFIX_SERVER, 587)
smtp.starttls()
else:
smtp = SMTP(POSTFIX_SERVER, POSTFIX_PORT or 25)
# smtp.send_message has UnicodeEncodeError
# encode message raw directly instead
try:
if POSTFIX_SUBMISSION_TLS:
smtp = SMTP(POSTFIX_SERVER, 587)
smtp.starttls()
else:
smtp = SMTP(POSTFIX_SERVER, POSTFIX_PORT or 25)
# smtp.send_message has UnicodeEncodeError
# encode message raw directly instead
smtp.sendmail(
from_addr,
to_addr,