Skip to main content
The BosonMail SDK supports HTML email content through the html field in SendEmailBody. You can send HTML-only, text-only, or both together. When you provide both, the API can present a multipart alternative that improves compatibility across email clients.

The html field

string
HTML content for the email body. Must be a non-empty string after trimming. Either text or html (or both) is required.

Why include both text and HTML

Email clients handle HTML differently. Some strip styles, others block external images, and a minority still prefer plain text. Providing both text and html gives the receiving server and client the option to display the most appropriate version.
The SDK sends both fields to the API when you provide them. It does not generate a text fallback from HTML automatically. Write the text version yourself for the best results.

Validation

The SDK enforces two rules for content fields:
  1. If text or html is present, it must be a string: 'text' and 'html' must be strings
  2. At least one must be non-empty after trimming: Email must contain text or HTML content

Practical HTML tips

Inline styles over external CSS

Most email clients ignore <style> blocks in the <head>. Use inline style attributes for reliable rendering.

Tables for layout

CSS Grid and Flexbox have limited support in email clients. Use HTML tables for complex layouts.

Absolute image URLs

Always use full https:// URLs for images. Relative paths and CID references are not supported by the SDK.

Escape user input to prevent HTML injection

If you interpolate user-provided data into HTML, escape it first. A simple helper:
lib/escape-html.ts
Never pass raw user input into HTML without escaping or sanitization. This prevents XSS-like injection in email clients that render HTML.

Full example

send-html.ts

Sending emails

Full sendEmail reference with parameters and validation rules.

Attachments

How to attach files to HTML and text emails.

Guides: HTML emails

Step-by-step guide for building rich email templates.

Error handling

How to handle validation and API errors.