Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Send HTML content in email #1589

Merged
merged 5 commits into from
Oct 3, 2023
Merged

✨ Send HTML content in email #1589

merged 5 commits into from
Oct 3, 2023

Conversation

foysalit
Copy link
Contributor

Using a very simple regex, check if the email content contains any html tags in it and send it as html, otherwise, fallback to plain-text content

@foysalit foysalit requested review from devinivy and dholms September 12, 2023 16:38
@bnewbold
Copy link
Collaborator

As a chronic user of text email (instead of HTML), it is nice when automated emails like this get sent as both text/plain and text/html. Markdown can go in text/plain and that would be what is expected in the content of the API request, with the server doing Markdown-to-HTML.

Alternatively, the Lexicon endpoint could have text and html fields to pass-through from client.

Or, have a contentType field in the Lexicon which can indicate if text or HTML (or markdown?); that wouldn't make sending both easy, but it might be better than auto-detecting HTML, which feels brittle.

All the above are ideas and could be done later; I wouldn't block merging this sniffing PR as-is.

@devinivy
Copy link
Collaborator

devinivy commented Sep 20, 2023

There is also a plugin for nodemailer, used on the server, that automatically generates the plaintext version of an email given an html email. I pretty much always use it when I'm using nodemailer! One option is to always treat emails as html (e.g. representing linebreaks with <br />), and let the plugin fill-in the plaintext version. https://www.npmjs.com/package/nodemailer-html-to-text

Relatedly, if we take the approach here, will the HTML content being sent-up represent linebreaks properly? For example, this content represented in HTML may not look right to users due to how whitespace gets collapsed:

Hi all,
Have you seen <i>A Midsummer Night's Dream</i>?

Best,
divy

Another option is to assume all email contents are markdown, and send an HTML version compiled from markdown with that plugin 👆 generating a plaintext version. That might be a convenient way to author marked-up email contents without needing to scatter <p>...</p> and <br /> all over the place.

@devinivy
Copy link
Collaborator

Ohp, just saw the PR to author emails in markdown on the client! In which case yeah, I think the move might be to:

  • author all emails in markdown on the client.
  • compile email markdown to html on the client, and treat all emails as html on the server (or explicitly indicate the content type, as @bnewbold suggested).
  • use the nodemailer-html-to-text plugin to provide a plaintext version of all emails.

@foysalit
Copy link
Contributor Author

@devinivy ok so I think treating all incoming content as html is the easiest option and I am not seeing a case where we would need to explicitly send plaintext content so adding contentType param just to facilitate that feels like unnecessary bloat right now.

@foysalit
Copy link
Contributor Author

@devinivy can I get one more look at this please? thanks!

@devinivy devinivy merged commit 26538a7 into main Oct 3, 2023
10 checks passed
@devinivy devinivy deleted the html-email-content branch October 3, 2023 15:17
mloar pushed a commit to mloar/atproto that referenced this pull request Nov 15, 2023
* ✨ Send HTML content in email

* ✨ Use html-to-text plugin for moderation mailer transport

* type fix

---------

Co-authored-by: Devin Ivy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants