Skip to main content
Most email clients render HTML, but some users prefer or require plain text. This guide shows you how to build a reusable, typed order-confirmation function that renders both HTML and plain text from structured data, escapes user values, and sends the result through the BosonMail SDK.

Why both HTML and text matter

The BosonMail SDK accepts text and html together in the same sendEmail call. Providing both improves compatibility across clients and accessibility tools. The SDK does not include a template engine: you build the markup in your own application code.

Define the email data shape

Start with a TypeScript interface so the renderer is type-safe and reusable.
types.ts

Escape helper

User-supplied values must be escaped before they reach HTML or text output.
escape.ts

Render HTML with inline styles

Build a narrow HTML table layout. Keep styles inline because many clients ignore <style> blocks in <head>.
render-html.ts

Render plain text

Produce a matching plain-text version for clients that do not render HTML.
render-text.ts

Send the email

Wire the renderer into a reusable sender function.
send-order-confirmation.ts

Usage example

example.ts

Testing tips across clients

Large HTML bodies increase rejection risk and slow rendering. Aim for under 100 KB of markup. Move heavy images to attachments or host them externally.
Use services such as Litmus or Email on Acid to preview how your table-based layout renders in Outlook, Gmail, Apple Mail, and mobile clients. Inline styles are the safest cross-client approach.
Many email clients strip <style> blocks and ignore @font-face. Use system font stacks and inline style attributes on every element that needs styling.
Run your HTML through a validator or linter to catch unclosed tags and broken tables. A malformed email may still be accepted by the API but render poorly for the recipient.
The SDK does not provide template features such as partials, loops, or layout inheritance. If you need those, bring your own template engine (for example, Handlebars, EJS, or React email renderers) and pass the final strings to sendEmail.

Next steps

Sending with attachments

Attach PDF invoices and CSV exports to your order confirmations.

Multiple recipients

Send the same confirmation to billing and shipping contacts using CC and BCC.

Monitoring delivery

Track whether the confirmation was delivered, bounced, or deferred.

SDK reference: HTML emails

Read the concise SDK reference for the html and text body options.