The text/plain part is not optional
Plenty of sending pipelines generate HTML only, let the library add an empty text part, and move on. It works until a recipient client renders the empty part, or a filter scores the message as suspicious for having no readable alternative. What the text part is for It is the fallback for clients that do not render HTML, the accessible version for screen readers, and a signal that the message was…
Many email sending systems only create HTML content, relying on libraries to generate an empty text version and then continue. This method is effective until a recipient's client displays the empty text part or a filtering system flags the message as suspicious due to the lack of a readable alternative. The purpose of the text part is two-fold: it serves as a fallback for clients that do not render HTML, provides an accessible version for screen readers, and signals that the message was carefully composed rather than bulk-sent.
A properly formatted multipart/alternative email with both text and HTML parts appears as a message a human would send. To achieve this, avoid stripping tags from the HTML during send time – URL links disappear, and the result becomes unreadable. Instead, compose the text version in tandem with the HTML: maintain identical paragraphs, transform links into "label https://url", and represent lists using dashes. Utilize a template, not a converter, to streamline the process.
One common pitfall is the line-length trap. Text bodies should wrap at 78 characters. A single 400-character paragraph in the text part appears as an unwieldy single line in some clients and can even be misinterpreted by filters that consider long lines as machine-generated. Wrap the text at composition time to prevent this issue.
Lastly, ensure that no template placeholders remain in the text part after rendering. For instance, a stray "{{first_name}}" can render the message as broken, rendering the fallback ineffective. Verify in the test suite that no braces survive rendering, not in production.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.