diff --git a/changelog.d/596.bugfix b/changelog.d/596.bugfix new file mode 100644 index 00000000..1c657610 --- /dev/null +++ b/changelog.d/596.bugfix @@ -0,0 +1 @@ +Prevent bare line feed rejection errors by using CRLF line endings when sending emails. Contributed by @NICO-SOLUTIONS. \ No newline at end of file diff --git a/sydent/util/emailutils.py b/sydent/util/emailutils.py index 5ad9b35a..29ae5a05 100644 --- a/sydent/util/emailutils.py +++ b/sydent/util/emailutils.py @@ -126,7 +126,11 @@ def sendEmail( # failing it may munge the address it returns. So we should *not* use # that parsed address, as it may not match any validation done # elsewhere. - smtp.sendmail(mailFrom, mailTo, mailString.encode("utf-8")) + # Replace the line endings (typically "\n") with "\r\n" (CRLF) as required by email. + # This avoids "550 5.6.11 SMTPSEND.BareLinefeedsAreIllegal" errors when + # sending to strict mail servers. + mailStringCRLF = "\r\n".join(mailString.splitlines()) + smtp.sendmail(mailFrom, mailTo, mailStringCRLF.encode("utf-8")) smtp.quit() except Exception as origException: if log_send_errors: