Email.send from zitejs/email. You write the content as HTML, and the
platform sanitizes it, frames it in the app’s brand kit, and generates a plain-text part. Use it for
confirmations, receipts, notifications and digests.
Set up the email integration
Sending always goes through theemail integration. Add it to the workspace root zite.config.json, with
Zite’s own sender as the provider:
setup_integration and pick Gmail or Outlook as the provider. The standalone gmail
and outlook integrations are for reading and managing a mailbox, not for sending.
zitejs/email is generated once the app has an email settings entry in its own zite.config.json. An
empty entry is enough:
fromName, fromEmail and replyTo. See
App config.
Send an email
Email.send({ to, subject, html }) sends an email written in HTML. Call it from a server function’s handler
or a *.server.ts helper, never from a page.
Read the result:
warnings lists problems that didn’t stop the send, such as a hand-built button or an
email large enough for Gmail to clip. Fix them before you ship the email.
What happens to your HTML at send time
- It’s sanitized. Scripts, forms, inputs, iframes, video, SVG, event handlers,
javascript:links anddata:images are removed. - Rules in any
<style>block are inlined into your markup only, so a rule liketd { padding: 8px }never touches the frame around it.@mediarules stay in the head. <a class="button" href="...">Label</a>becomes a button that keeps its padding and colour in Outlook.- It’s framed according to
layout:'formatted'(the default): a content card on a tinted background, under the logo, in the app’s brand kit colours, font and button radius. Without a brand kit the frame is neutral. This is the right choice for nearly every app email.'plain': no card and no logo, like a note typed by a person. Good for internal notifications and personal follow-ups.
- A plain-text part is generated from it, with links written out. Pass
textonly when the plain version needs different wording.
Email.send rather than painting it in your HTML.
background is the colour around the card (or behind a plain email’s text, as a sheet the width of the
column), and cardBackground is the card’s. Both are hex, both default to the brand kit, and text on them
is kept readable. A coloured box drawn inside the card instead leaves the brand’s colours around it, so the
email shows three backgrounds.
Rules, and why
- Lay out with tables. Outlook on Windows renders email with Word: no flexbox, grid, float or
positioning, and
max-widthon a<div>is ignored. Columns are<td>s in a<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">. Plain<p>,<h1>to<h3>,<ul>and<div>are fine for text. - Space with padding on
<td>, not margins on<div>s, which Outlook drops. Reset text margins inline, for example<p style="margin:0 0 16px;">. A paragraph you leave without one gets 16px below it. - Your HTML is the content, not the page. Don’t wrap it in an outer table, padding, a fixed or
centred width, or a background: the frame sets the width and spacing for each layout. A plain email has
none, so it reads like one someone typed. A plain email with a
backgroundgets the sheet’s padding, and a formatted one gets the card’s. A wrapper of your own adds a second margin, which makes a plain note look generated and puts a box inside the card. Inside, the content is about 560px wide in the card and up to 640px in a plain email, so size images and columns as fractions ofwidth="100%". - Colours are hex (
#0f766e). Gmail drops CSS variables, and Outlook ignoresrgba(),hsl()andoklch(). On a coloured table cell, set bothbgcolor="#f1f5f9"andbackground-color: the attribute is what Outlook reads. - Text. Use font sizes in px (body 16px, 14px at the smallest for fine print, headings 20 to 28px),
and
line-heightin px or unitless. Leavefont-familyand the text colour to the frame: it picks a colour that reads on the brand kit’s card, light or dark, and a hardcoded dark grey disappears on a dark brand. Where you do colour text, also set the background behind it (a badge, a panel), so it reads on any card. - Images take absolute
https://URLs, awidthattribute,alttext, andstyle="display:block;max-width:100%;height:auto;border:0;". Many clients block images until the reader allows them, so nothing important may live only in an image: no text baked into pictures, and no image-only emails (spam filters score those badly too). Use an<img>rather thanbackground-image, which Outlook ignores. - Buttons are
<a class="button" href="https://...">Label</a>, on their own line rather than inside a<p>. Don’t build your own from a padded link:class="button"is what gives it the Outlook version and the brand’s colour. Aclass="button"link takes the brand’s primary colour. An inlinebackground-color,colororborder-radiusoverrides it, and other inline styles on it are dropped. Align it withtext-alignon the element around it. A link you pad and fill yourself is sent as written, so Outlook desktop shows it as a thin coloured strip, andEmail.sendreturns a warning naming it. Give an email one primary action. - Links are absolute:
https://,mailto:ortel:. Build app links fromprocess.env.ZITE_APP_URL. Link text says where it goes (“View your booking”), never “click here”, and a link inside a sentence keeps its underline so it doesn’t rely on colour alone. - Escape every interpolated value with a small
escapeHtmlhelper that encodes&,<,>,"and'. That includes names, notes, and anything a user typed. Unescaped input breaks the layout and lets a user inject links into an email sent from the app. URLs from data go throughescapeHtmltoo. - Recipients come from your data. Anyone who can reach a server function can call it with any input. A function that sends to an address, or with wording, taken straight from its input lets them use the app to email anyone anything. Take an id, load the record, and send to the address stored on it, or to the signed-in user.
- Replies. Zite’s sender sends from a no-reply address, so replies go nowhere unless a reply-to is
set. With Gmail, Outlook or SMTP, replies come back to that mailbox. When an email invites a reply (a
booking, an order, a support question) and the app uses Zite’s sender, decide where replies should go.
An address for every email from the app goes in the email integration’s
replyTosetting (the Reply-to field beside From name in its settings). PassreplyTotoEmail.sendwhen it differs per email, such as the staff member who owns a booking. - Numbers and dates. Coerce with
Number(...)and checkNumber.isFinitebefore formatting. Format money withIntl.NumberFormatand dates withIntl.DateTimeFormat, passing thetimeZoneexplicitly. Server code runs in UTC, so a baretoLocaleString()shows the wrong day near midnight. - Mobile. Most email is read on phones, and narrow clients shrink a 600px table to fit. Keep to two
columns at most. To stack columns on small screens, give each column
<td>a class and add@media only screen and (max-width: 600px) { .stack { display: block !important; width: 100% !important; } }in a<style>block. Outlook desktop ignores@mediaand keeps the columns, so they must read well side by side too. - Preview text. The inbox shows the first text of the email next to the subject. To choose it, start
the HTML with
<div style="display:none;max-height:0;overflow:hidden;">One line summary</div>. It’s left out of the plain-text part. - Dark mode. Gmail’s iPhone and Android apps and Outlook (Windows, Outlook.com and its phone apps) may invert light backgrounds and dark text. Prefer clear contrast over subtle greys, and don’t put dark text directly on a transparent image.
- Size. Gmail clips emails over 102 KB behind “View entire message”.
Email.sendreturns a warning from about 90 KB, since Gmail measures after encoding. For long lists (hundreds of rows), show a summary and the first few items, and link to the app for the rest. - Subject. Keep it specific and under about 60 characters, for example “Order #1042 shipped” rather than “Update”. Write in plain words: ALL CAPS and many exclamation marks read as spam.
- Language. Pass
langon every send with the language the email is written in ('en','es','pt-BR'). Without it, Gmail and other webmail give the content no language, so screen readers and translation have to guess.
Example: booking confirmation
The server function takes only an id. The recipient and every value in the email come from the database.Patterns
These building blocks follow the rules above. They draw lines rather than fill boxes, so the frame’s text colour reads on a light or a dark card. Stats row: up to three figures side by side, stacked on phones with the.stack rule from rule 13.
border-right in a right-to-left email.
Older emails that use body
Emails written before HTML support pass body, an array of blocks, instead of html. They keep working,
so leave them as they are. To change one, rewrite its blocks as HTML following the rules above: a button
block becomes <a class="button">, and a spacer becomes padding.
Keep logo, direction, attachments, cc, bcc and replyTo as they were. A logo passed to
Email.send replaces the brand kit’s logo, so drop it when it’s the brand logo, and the email follows the
brand kit.
Check your work
Send a test to your own address to see the email in a real inbox. ReadEmail.send’s result, and fix
anything in its warnings before you finish.