From 772c43bc67a54c453738b6ac10fe8bbfac0a4b27 Mon Sep 17 00:00:00 2001 From: Nils Coenen Date: Fri, 13 Jun 2025 18:57:46 +0200 Subject: [PATCH 1/6] [IMP] Prevent bare line feed rejection errors - Use CRLF line endings to avoid 550 5.6.11 SMTP errors Signed-off-by: Nils Coenen --- changelog.d/550-email-crlf.md | 3 +++ sydent/util/emailutils.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelog.d/550-email-crlf.md diff --git a/changelog.d/550-email-crlf.md b/changelog.d/550-email-crlf.md new file mode 100644 index 00000000..705ed6c1 --- /dev/null +++ b/changelog.d/550-email-crlf.md @@ -0,0 +1,3 @@ +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..5751183a 100644 --- a/sydent/util/emailutils.py +++ b/sydent/util/emailutils.py @@ -126,7 +126,8 @@ 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")) + mailStringCRLF = "\r\n".join(mailString.splitlines()) + smtp.sendmail(mailFrom, mailTo, mailStringCRLF.encode("utf-8")) smtp.quit() except Exception as origException: if log_send_errors: From 3178367101639b9970f90b8fc507a099e4a7617a Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Thu, 17 Jul 2025 11:33:42 +0100 Subject: [PATCH 2/6] Apply suggestions from code review --- changelog.d/550-email-crlf.md | 4 +--- sydent/util/emailutils.py | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/changelog.d/550-email-crlf.md b/changelog.d/550-email-crlf.md index 705ed6c1..602d8cf8 100644 --- a/changelog.d/550-email-crlf.md +++ b/changelog.d/550-email-crlf.md @@ -1,3 +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 +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 5751183a..9fae1d21 100644 --- a/sydent/util/emailutils.py +++ b/sydent/util/emailutils.py @@ -126,8 +126,12 @@ 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. + # 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.sendmail(mailFrom, mailTo, mailStringCRLF.encode("utf-8")) smtp.quit() except Exception as origException: if log_send_errors: From fd091c7d52d53fa87ed8767fee0b055ed53e1495 Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Thu, 17 Jul 2025 11:34:30 +0100 Subject: [PATCH 3/6] Changelog entries must end with punctuation --- changelog.d/550-email-crlf.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/550-email-crlf.md b/changelog.d/550-email-crlf.md index 602d8cf8..1c657610 100644 --- a/changelog.d/550-email-crlf.md +++ b/changelog.d/550-email-crlf.md @@ -1 +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 +Prevent bare line feed rejection errors by using CRLF line endings when sending emails. Contributed by @NICO-SOLUTIONS. \ No newline at end of file From ed934fbe429776cfa20bd1748cde3f72ed288291 Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Thu, 17 Jul 2025 11:35:03 +0100 Subject: [PATCH 4/6] =?UTF-8?q?Remove=20duplicated=20line=20=F0=9F=A4=A6?= =?UTF-8?q?=E2=80=8D=E2=99=82=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sydent/util/emailutils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sydent/util/emailutils.py b/sydent/util/emailutils.py index 9fae1d21..29ae5a05 100644 --- a/sydent/util/emailutils.py +++ b/sydent/util/emailutils.py @@ -131,7 +131,6 @@ def sendEmail( # sending to strict mail servers. mailStringCRLF = "\r\n".join(mailString.splitlines()) smtp.sendmail(mailFrom, mailTo, mailStringCRLF.encode("utf-8")) - smtp.sendmail(mailFrom, mailTo, mailStringCRLF.encode("utf-8")) smtp.quit() except Exception as origException: if log_send_errors: From 073a191e300b4b0f0c151b649f2f37881a1ad716 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Thu, 17 Jul 2025 11:43:03 +0100 Subject: [PATCH 5/6] newsfiles must be named the PR # "." entry type --- changelog.d/596.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/596.bugfix 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 From f09e6b323d40373f7529e79c1f2b66a45b70af23 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Thu, 17 Jul 2025 11:44:20 +0100 Subject: [PATCH 6/6] Delete old newsfile --- changelog.d/550-email-crlf.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 changelog.d/550-email-crlf.md diff --git a/changelog.d/550-email-crlf.md b/changelog.d/550-email-crlf.md deleted file mode 100644 index 1c657610..00000000 --- a/changelog.d/550-email-crlf.md +++ /dev/null @@ -1 +0,0 @@ -Prevent bare line feed rejection errors by using CRLF line endings when sending emails. Contributed by @NICO-SOLUTIONS. \ No newline at end of file