fix(smtp): preserve <br> line breaks in HTML emails#1620
Merged
binwiederhier merged 1 commit intoFeb 21, 2026
Conversation
HTML-only emails (e.g. from Synology DSM 7.3 Task Scheduler) use <br> tags for line breaks. The existing implementation passed the raw HTML body to bluemonday with AddSpaceWhenStrippingTag(true), which replaced every tag including <br> with a space, causing all content to appear on a single unreadable line. Fix: convert <br> tags to newlines before stripping HTML, so line break semantics are preserved in the notification body. Resolves the gap noted in binwiederhier#690 ("very sub-par" HTML support).
Owner
|
This is a reasonable fix. Thank you @uzkikh and Cursor/Claude :-) |
alexlebens
pushed a commit
to alexlebens/infrastructure
that referenced
this pull request
Mar 8, 2026
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [binwiederhier/ntfy](https://github.com/binwiederhier/ntfy) | minor | `2.17.0` → `2.18.0` | | [binwiederhier/ntfy](https://ntfy.sh/) ([source](https://github.com/binwiederhier/ntfy)) | minor | `v2.17.0` → `v2.18.0` | --- ### Release Notes <details> <summary>binwiederhier/ntfy (binwiederhier/ntfy)</summary> ### [`v2.18.0`](https://github.com/binwiederhier/ntfy/releases/tag/v2.18.0) [Compare Source](binwiederhier/ntfy@v2.17.0...v2.18.0) This is the biggest release I've ever done on the server. It's 14,997 added lines of code, and 10,202 lines removed, all from one [pull request](binwiederhier/ntfy#1619) that adds [PostgreSQL support](https://docs.ntfy.sh/config/#postgresql-experimental). The code was written by Cursor and Claude, but reviewed and heavily tested over 2-3 weeks by me. I created comparison documents, went through all queries multiple times and reviewed the logic over and over again. I also did load tests and manual regression tests, which took lots of evenings. I'll not instantly switch ntfy.sh over. Instead, I'm kindly asking the community to test the Postgres support and report back to me if things are working (or not working). There is a [one-off migration tool](https://github.com/binwiederhier/ntfy/tree/main/tools/pgimport) (entirely written by AI) that you can use to migrate. **Features:** - Add experimental [PostgreSQL support](https://docs.ntfy.sh/config/#postgresql-experimental) as an alternative database backend (message cache, user manager, web push subscriptions) via `database-url` config option ([#​1114](https://github.com/binwiederhier/ntfy/issues/1114)/[#​1619](https://github.com/binwiederhier/ntfy/pull/1619), thanks to [@​brettinternet](https://github.com/brettinternet) for reporting) **Bug fixes + maintenance:** - Preserve `<br>` line breaks in HTML-only emails received via SMTP ([#​690](binwiederhier/ntfy#690), [#​1620](binwiederhier/ntfy#1620), thanks to [@​uzkikh](https://github.com/uzkikh) for the fix and to [@​teastrainer](https://github.com/teastrainer) for reporting) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My41OS4yIiwidXBkYXRlZEluVmVyIjoiNDMuNTkuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiaW1hZ2UiXX0=--> Reviewed-on: https://gitea.alexlebens.dev/alexlebens/infrastructure/pulls/4523 Co-authored-by: Renovate Bot <renovate-bot@alexlebens.net> Co-committed-by: Renovate Bot <renovate-bot@alexlebens.net>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
HTML-only emails (e.g. from Synology DSM 7.3 Task Scheduler) use
<br>tags for line breaks. The existing implementation passed the raw HTML body to bluemonday withAddSpaceWhenStrippingTag(true), which replaces every tag including<br>with a space. This caused all notification content to appear on a single unreadable line.The ntfy notification before the fix
Task Scheduler has completed a scheduled task. Task: daily-backup Start time: Mon, 01 Jan 2026 02:00:00 +0000 Current status: 0 (Normal) From MyNAS
The ntfy notification after the fix
Task Scheduler has completed a scheduled task.
Task: daily-backup
Start time: Mon, 01 Jan 2026 02:00:00 +0000
Current status: 0 (Normal)
From MyNAS
Steps to reproduce
Root cause
The
readHTMLMailBody()function usedbluemonday.StrictPolicy().AddSpaceWhenStrippingTag(true)which replaces all tags including<br>with spaces, discarding line break semantics.Fix
Convert
<br>tags to newlines before passing to bluemonday. The regex covers all variants:<br>,<BR>,<br/>,<BR />.Tests
TestSmtpBackend_HTMLOnly_FromDiskStationandTestSmtpBackend_HTMLEmailto reflect correct outputTestSmtpBackend_HTMLEmail_BrTagsPreservedcovering the Synology Task Scheduler email formatRelated to #690