Messaging
Every message your site or app sends its own users, from one place: transactional email from an API call, sequences that start on a sign-up or an event, newsletters and blasts, push to your iPhone and Android apps, and in-app messages through the Pagebee messenger. Each message has a delivery log, preferences are honoured on every send, and marketing mail gets its unsubscribe link and headers without you writing them.
Everything here works from the dashboard (a site or app's Messaging tab), the HTTP API and MCP, so your coding agent can set it up. Email goes out through Resend on Pagebee's account: you don't need a Resend account, and Pagebee never runs mail servers of its own.
SMS is designed in (a channel, a preference and a template shape) but isn't available yet. A send or sequence step on SMS is refused with the reason "SMS isn't available yet".
Concepts
| Term | Means |
|---|---|
| Contact | Someone you know: your own user, a waitlist sign-up, a newsletter subscriber or a person who wrote to support. Found by your user_id, their email, or both |
| Stream | Transactional is what someone asked for: receipts, sign-in links, password resets. Marketing is everything else, and always carries an unsubscribe |
| Channel | Email, push, in-app, or SMS (not available yet) |
| Topic | A kind of marketing mail people can turn off on its own, like product-updates or tips |
| Preferences | Each contact's marketing consent, channel switches and topic switches, checked before every send |
| Template | One message for one channel, addressed by a key from your code, with {{variables}} |
| Sequence | Messages sent over time after a trigger, with waits, branches and a goal that ends it early |
| Segment | A saved filter over contacts: properties, events, waitlist status, plan, consent, age, and what they did with earlier messages |
| Newsletter | A one-off email to everyone, a segment or a topic, kept in a public archive |
| Blast | The same, without the archive: an announcement, an outage notice, a push to every phone |
Contacts and consent
Contacts added from your server start subscribed to marketing unless you send "subscribed": false. Newsletter sign-ups are subscribed once they confirm (double opt-in is on by default). People who only wrote to support are neither: they get replies and transactional mail, never marketing.
Contacts are never joined to anonymous web sessions or the daily visitor hash. Events about a contact come only from your server.
Templates and variables
Write {{name}} anywhere in a subject, a block, HTML, a push title or body. Values are escaped, so a contact's name can never add markup or a link. Give a fallback for when the value is empty:
Hi {{first_name | "there"}},Values come from the data you send, then the contact. Built in, without being given: {{first_name}}, {{name}}, {{email}}, {{user_id}}, {{site_name}}, {{unsubscribe_url}} and {{preferences_url}}. A contact's properties are under user, like {{user.plan}}. A template's preview lists every variable it uses and the ones with no value.
Email templates are visual (blocks: heading, text, button, image, list, quote, divider, spacer) or code (your own HTML). In text blocks, **bold**, *italic*, [links](https://...) and variables work. The plain text version is worked out for you unless you give one. Writing a template with a key that exists changes it in place, so pushing the same file twice changes nothing.
Sequences
A sequence starts on one trigger:
| Trigger | Starts when |
|---|---|
signup | A new contact arrives from your server, or a newsletter sign-up confirms |
waitlist_join | Someone joins the waitlist: a response to your waitlist form, or "waitlist": "joined" from your server |
event | An event with that name: POST /v1/messaging/events, or a server event whose uid is the contact's user id |
property_change | A property changes, to anything or to a value you name |
date | A date property comes round, offset by days: trial_ends_at minus 3 days. Checked hourly, sent from the hour you choose in UTC |
manual | Only through the API or MCP |
Steps are email, push, in_app (each names a template), wait (days, hours, minutes), branch (a condition, then steps for yes and for no) and exit. An audience filter decides who may enter. A goal takes people out as soon as it's true (they upgraded, they activated) and counts as a conversion. reentry lets someone who finished start again.
Five recipes come with their templates: welcome, onboarding nudges, waitlist launch, trial ending and win-back. Start from one in the Messaging tab, with create_sequence_from_recipe, or POST .../sequences/from-recipe.
Segments
Segments, sequence branches and goals share one condition language. Match all or any of up to 20 conditions:
| Condition | Example |
|---|---|
property | plan is pro, trial_ends_at before 2026-12-01, company exists |
event | Did exported_report, or didn't, in the last 14 days |
waitlist | is joined, is invited, is converted |
plan | Shorthand for the plan property |
subscription | subscribed, unsubscribed or not_set |
created | A contact for under 7 days, or over 90 |
message | Opened, clicked, received, didn't open or didn't click a template (or any) |
{ "match": "all", "conditions": [
{ "type": "plan", "op": "is", "value": "free" },
{ "type": "event", "name": "exported_report", "op": "not_performed", "within_days": 30 }
] }Newsletters and blasts
Write them in the block editor, then send to everyone subscribed, a segment, or a topic, now or at a time you choose. They go out in batches. Newsletters are kept in a public archive at pagebee.ai/newsletter/<address>, with a subscribe form and a page per issue (variables blank, no tracking). Blasts aren't archived.
To take sign-ups on your own site, post the form to the subscribe address shown in Messaging settings:
<form action="https://api.pagebee.ai/v1/newsletters/<address>/subscribe" method="post">
<input type="email" name="email" required placeholder="you@example.com">
<input type="text" name="website" tabindex="-1" autocomplete="off" style="display:none">
<button>Subscribe</button>
</form>website is a trap for bots: leave it hidden and empty. The person lands back on your newsletter page, told to check their inbox. From JavaScript, post JSON { "email": "...", "name": "...", "website": "" } and you get { "ok": true, "confirm": true } when they need to confirm.
Quick start
1. Verify your domain. In the Messaging tab, add the domain you send from (or a subdomain like mail.example.com). Pagebee shows the DNS records to add and, when it recognises your DNS host (Cloudflare, GoDaddy, Namecheap, Route 53, Google), where to add them. Until it verifies, mail comes from Pagebee's shared address and the lower sending limit applies.
2. Create a template. In the tab, or with a dev key:
curl -X POST https://api.pagebee.ai/api/properties/<site id>/messaging/templates \
-H "Authorization: Bearer $PAGEBEE_DEV_KEY" -H "Content-Type: application/json" \
-d '{
"key": "welcome",
"name": "Welcome",
"stream": "transactional",
"subject": "Welcome to Tally, {{first_name | \"there\"}}",
"blocks": [
{ "type": "heading", "text": "You are in" },
{ "type": "text", "text": "Your first report is ready. It takes a minute to set up the second." },
{ "type": "button", "label": "Open Tally", "url": "https://tally.studio/app" }
]
}'3. Send it from your server with the site's secret key:
curl -X POST https://api.pagebee.ai/v1/messaging/send \
-H "Authorization: Bearer pb_sk_your_secret_key" -H "Content-Type: application/json" \
-d '{ "template": "welcome", "to": { "user_id": "u_123", "email": "sam@example.com", "name": "Sam Lee" }, "idempotency_key": "welcome-u_123" }'{ "id": "6f1c...", "status": "queued", "reason": null, "duplicate": false }4. Check it arrived in the Messaging tab's log, or with GET /v1/messaging/messages/<id>.
Set it up with your agent
Paste this into Claude Code, Cursor or Codex, with the Pagebee MCP connected in dev mode:
Set up Pagebee Messaging for this app (use the Pagebee MCP, and the docs at https://pagebee.ai/docs/messaging.md).
1. Find where we send email today (password resets, receipts, sign-in links) and list each one.
2. For each, write a transactional template with write_message_template, keeping our wording, with {{variables}} for the values the code passes.
3. Replace each send in our code with a POST to /v1/messaging/send using PAGEBEE_SECRET_KEY from the environment, with an idempotency_key.
4. Where users sign up, POST /v1/messaging/contacts with their user_id, email, name and plan. Send our key product events to /v1/messaging/events.
5. Start the welcome and trial ending recipes with create_sequence_from_recipe and adapt their copy to our product. Leave them as drafts.
6. Tell me which DNS records to add for our sending domain, and send me a test of each template.HTTP API
All on https://api.pagebee.ai, JSON in and out. Authenticate with the site's secret ingest key (Authorization: Bearer pb_sk_...), which already names the site, or a dev API key (Authorization: Bearer pb_ak_...) plus "site_id" in the body (or site_id in the query for GET).
Send a message
POST /v1/messaging/send
| Field | Required | Meaning |
|---|---|---|
template | yes | The template's key |
to | yes | An email address, or { "user_id", "email", "name" } with at least a user id or an email. A new person becomes a contact |
data | no | Values for the template's variables: strings, numbers, booleans |
idempotency_key | no | A retry with the same key within a day sends nothing new and answers with the first message |
reply_to | no | An address replies go to, for this message only |
Answers { "id", "status", "reason", "duplicate" }. status is queued when it's on its way, or suppressed or failed with a reason when it went no further (an address that bounced, a contact who turned the channel off, a daily limit). A template's stream decides the rules: transactional ignores marketing consent but never goes to a suppressed address.
Read a message
GET /v1/messaging/messages/:id answers the logged message: channel, stream, status, recipient, subject, template, the time of each step (sent_at, delivered_at, opened_at, clicked_at, bounced_at, complained_at, unsubscribed_at) and events, its timeline with a detail line for each.
Add or update a contact
POST /v1/messaging/contacts
{ "user_id": "u_123", "email": "sam@example.com", "name": "Sam Lee", "properties": { "plan": "trial", "trial_ends_at": "2026-12-10" }, "waitlist": "none" }| Field | Meaning |
|---|---|
user_id, email | At least one. Matched on either |
name | Their name; first_name is worked out from it |
phone | International format (+447700900123), kept for SMS later |
properties | Up to 50. Strings, numbers or booleans; null removes one. Dates as ISO strings |
subscribed | Marketing consent. Leave it out to keep what's held |
waitlist | none, joined, invited or converted |
Answers { "contact", "created" }. A new contact starts signup sequences; a changed property starts property_change ones; "waitlist": "joined" starts waitlist_join ones.
Record an event
POST /v1/messaging/events with { "user_id" or "email", "name", "properties", "at" }. Answers { "ok": true, "sequences_started": 1 }. Events start event sequences and feed segments, branches and goals.
Server events sent to /v1/events with a uid equal to the contact's user id count too, so you don't need to send the same thing twice.
Register a phone for push
POST /v1/messaging/devices with { "user_id", "token", "platform": "ios" or "android", "environment": "production" or "sandbox" }. Call it from your server when your app hands you its push token. sandbox is for iOS debug builds. Answers { "ok": true }.
Start a sequence by hand
POST /v1/messaging/sequences/:key/enroll with { "user_id" or "email", "data" }. Answers { "enrolled": true, "reason": null }, or false with why (already in it, outside its audience, the sequence is paused).
In-app messages
GET /v1/messaging/in-app?user_id=u_123 answers { "messages": [{ "id", "title", "body", "url", "created_at", "read_at" }] }, newest first, for drawing an inbox in your own app. POST /v1/messaging/in-app/:id/read marks one read.
The dashboard API
The Messaging tab runs on /api/properties/:id/messaging, which also takes a dev key (Authorization: Bearer pb_ak_...). The main routes:
| Method and path | What it does |
|---|---|
GET, PUT .../messaging | Settings: senders, postal address, tracking, topics, newsletter, and the current sending limits |
PUT .../messaging/push | Push credentials (APNs or Firebase). Write only |
POST .../messaging/domains, POST .../domains/:id/verify, DELETE .../domains/:id | Add a sending domain and get its DNS records, check them, remove it |
GET, POST .../messaging/templates, GET, PATCH, DELETE .../templates/:key | Templates. POST .../templates/:key/preview renders one, .../test sends a test |
GET, POST .../messaging/sequences, GET, PATCH, DELETE .../sequences/:id | Sequences. PATCH with status sets live, paused or draft. GET .../sequences/recipes and POST .../sequences/from-recipe |
GET, POST .../messaging/broadcasts, GET, PATCH, DELETE .../broadcasts/:id | Newsletters and blasts. GET .../preflight, POST .../send (with send_at to schedule), POST .../cancel, POST .../test |
GET, POST .../messaging/segments, PATCH, DELETE .../segments/:id | Segments. POST .../segments/preview counts a filter |
GET, POST .../messaging/contacts, GET, PATCH .../contacts/:id | Contacts, searchable and filtered by segment or consent, with their events, messages and sequences |
GET .../messaging/log, GET .../log/:id | The message log, filtered by status, channel, stream, template, newsletter, sequence, contact or words |
GET .../messaging/report?days=30 | Sent, delivered, opened, clicked, bounced, complained, unsubscribed and converted, with rates, by day, template, sequence and newsletter |
POST .../messaging/draft | AI drafting: an email or subject lines from a brief |
Delivery statuses
Every message is one row in the log, whatever the channel, with a timeline:
| Status | Means |
|---|---|
queued | Accepted and waiting to go |
sent | Handed to the mail service, Apple or Google |
delivered | The receiving mail server took it |
opened | The open image loaded. Approximate: some mail apps load images for everyone, some for no one |
clicked | A link was followed |
bounced | The address doesn't take mail. It's suppressed from then on |
complained | The person marked it as spam. They're suppressed, and a marketing complaint unsubscribes them |
failed | It couldn't be sent; the reason says why |
suppressed | Not sent: a suppressed address, no consent, a channel or topic turned off, or a limit |
Opens and clicks are counted by Pagebee itself: an image at the end of the email and a signed redirect for each link, so nobody can use it as an open redirect. Switch either off in Messaging settings. Unsubscribe and preferences links are never rewritten.
Compliance and sending limits
Marketing mail gets these without you writing them:
- An unsubscribe link and a link to the person's preferences page at
pagebee.ai/preferences/<token>. List-UnsubscribeandList-Unsubscribe-Post: List-Unsubscribe=One-Clickheaders, so mail apps show their own unsubscribe button and it works in one click (RFC 8058).- Your postal address in the footer. Set it in Messaging settings; the preflight checks for it before a newsletter or blast goes.
Bounces and complaints suppress the address automatically, for every stream. Transactional and marketing can come from different addresses (often a subdomain like news.example.com for marketing), so one stream's reputation doesn't drag down the other.
Sending is limited by tier, per site, per day, with a largest single newsletter or blast:
| Tier | When |
|---|---|
| New | The first week, or no verified sending domain |
| Standard | After that, with a verified domain |
| Established | An account with a longer sending history |
The Messaging tab and GET .../messaging show your tier, today's limits and what's been sent. Marketing pauses itself if complaints pass 0.3% or bounces pass 5% over 30 days.
Before a newsletter or blast goes, a preflight checks the sending domain, the postal address, the audience size against your tier, the unsubscribe link, the links and the subject. A warning goes ahead and says so; a block stops the send until it's fixed. GET .../broadcasts/:id/preflight runs it on its own.
Push
Push goes to your own iPhone and Android apps.
- Add your keys in Messaging settings, Push. For iOS, an APNs key: the
.p8file's contents, its key ID, your team ID and the app's bundle ID. For Android, a Firebase service account JSON. They're stored and never shown again. - Register devices from your server with
POST /v1/messaging/deviceswhen your app sends you its push token, with the user id you know them by. - Send with a push template, a sequence step or a blast. A person with no registered phone, or who turned push off, is skipped with a reason in the log.
In-app
In-app messages arrive in the person's messenger, in the conversation they already have with you, and in GET /v1/messaging/in-app for an inbox of your own. They need the messenger on your site and the person identified with a signed token: see signed-in people. The token's sub must be the same user id you use here.
AI drafting
With Pagebee's AI on, the editor can draft an email or suggest subject lines from a sentence or two, in a friendly, plain, excited or formal tone. You edit what it writes; nothing sends by itself. Over MCP, draft_email does the same. Where the AI isn't on, the button doesn't show.
MCP tools
Every mode sees list_message_templates, list_sequences, list_broadcasts, list_segments and get_messaging_report. Contacts and the delivery log hold people's details, so list_messaging_contacts and get_message_log need a support or dev key. Dev mode adds the rest.
| Tool | Mode | What it does |
|---|---|---|
list_message_templates | Every mode | Templates with their variables and numbers |
write_message_template | Dev | Write a template. The same key again changes it in place |
send_message | Dev | Send a template to one person, like the send API |
list_sequences | Every mode | Sequences with their steps, who's in them, and conversion |
write_sequence | Dev | Write a sequence: trigger, steps, audience and goal |
create_sequence_from_recipe | Dev | Start from welcome, onboarding, waitlist launch, trial ending or win-back, with templates |
list_broadcasts | Every mode | Newsletters and blasts, drafts to sent, with their numbers |
write_broadcast | Dev | Write a newsletter or blast and its audience |
send_broadcast | Dev | Run the preflight, then send now or at a time |
list_segments | Every mode | Segments with their filters and sizes |
write_segment | Dev | Write a segment |
list_messaging_contacts | Support and dev | Contacts, by words, segment or consent |
upsert_messaging_contact | Dev | Add or update a contact |
get_message_log | Support and dev | The delivery log, or one message with its timeline |
get_messaging_report | Every mode | Open, click, conversion, unsubscribe and bounce rates over a period |
draft_email | Dev | Draft an email or subject lines from a brief, when Pagebee's AI is on |
Ask things like:
Why didn't sam@example.com get the password reset?
Write a newsletter about this month's releases from the changelog, to everyone on the product-updates topic. Leave it as a draft.
Which onboarding email has the worst click rate? Rewrite it.SMS
SMS is designed in: contacts have a phone number, preferences have an SMS switch and templates have an SMS shape. Sending isn't available yet, and every SMS send or step is refused with "SMS isn't available yet". This page will say when that changes.