How to let an AI agent send customer email without burning your domain
Your sending domain has one reputation. Your password resets, your receipts and your newsletter all draw on it, and so does any AI agent you give an email key. When the agent gets it wrong, the cost does not land on the agent. It lands on the next password reset that goes to spam.
This guide is for developers wiring an agent to email: a support agent that writes back to customers, a sales agent that follows up, a coding agent with an email tool. It covers what goes wrong, the guardrails that stop it, and how to set each one up. The principles apply to any email provider. The code and settings are PristineSend's.
What "burning your domain" means
Mailbox providers decide where your email lands from how people and servers react to it. Two numbers matter most:
- Bounces. Mail to addresses that do not exist tells Gmail and Microsoft you do not know who you are writing to.
- Spam complaints. Google and Yahoo require bulk senders to keep the spam rate they report under 0.3%, and Google tells senders to aim under 0.1%. See our guide to the spam complaint rate.
Push either one up for a few days and your mail starts landing in spam, for every kind of email you send from that domain. Recovering takes weeks of clean sending. An agent can push both up in an afternoon.
How agents go wrong
Agents do not fail like people. Four failures come up again and again:
- Loops. A retry, a re-triggered workflow or a confused plan sends the same message to the same person five, fifty or five hundred times. Each one after the first is a likely spam report.
- Invented and misspelt addresses. A model asked to "email Jane" will produce a plausible address.
jane@gmial.comandjane.smith@company.comlook fine and bounce. - Unfinished emails. A placeholder link,
[link](url), an empty image or no subject. A person would see it before sending. An agent sends it. - The wrong audience. "Email the trial users from this week" becomes "email all users". A person sees the count on a confirmation screen. An agent does not stop to look.
A prompt that says "be careful" fixes none of these. The guardrails have to sit below the agent, in the platform, where the agent cannot talk its way past them.
1. Give the agent its own key, with the fewest permissions
Do not hand the agent your application's API key. Create a key for the agent alone, so that you can:
- see exactly what it sent;
- turn on the stricter rules below for it without touching your password resets;
- revoke it without taking your product down.
Give it only the permissions it needs. In PristineSend you choose them when you create the key in Settings → Developer. A key with only email:send can send email through POST /api/v1/send and /send/batch and nothing else: it cannot read your contact list, change your do-not-send list or draft a campaign.
Two permissions are never given to an agent connected through MCP, whatever you set as the default: email:send_bulk (draft a campaign to a whole segment) and segments:write (create a segment). Together they would let an agent build an audience and mail it. They exist only on an API key you create on purpose. In a new account, a newly connected agent can read the account, check an email's deliverability, send email and start automations you have already turned on; you can narrow that per agent in Settings.
2. Build against a sandbox, not your customers
Develop and test the agent with a ps_test_ key. A test key goes through the same checks as a live one (the sender, the fields, the do-not-send list) and answers the same way, but nothing is delivered and nothing counts against your plan. The email shows in your logs with a Test badge.
The point is to see the agent's mistakes before a customer does. Run your evaluation set against the test key, read what it tried to send, and only then swap in a live key. See Test mode.
3. Cap how many emails one person can get, and stop loops
This is the guardrail that matters most for agents, because a loop is the failure that does the most damage fastest.
PristineSend counts the emails each address gets from your account and refuses the next one past a limit: 5 in 24 hours and 15 in 7 days unless you change them, in Settings → Workspace → Emails per contact. On top of that, the third near-identical email to one address within 10 minutes is refused. That rule is what stops a loop at its third email, before it becomes a hundred.
Campaigns and automations always count. For API email the limit applies to:
- every agent connected through MCP, always;
- any API key you set to count (a choice when you create the key, and on the key list afterwards).
A password reset from an ordinary key is never limited, so turning this on cannot lock a customer out of your product.
A refused email answers 422 recipient_cap_reached or 422 recipient_burst, nothing is sent, and the log says why. Tell your agent what those mean (see section 7): the right response is to stop and report, not to retry. Details in Rate limits.
4. Refuse unfinished emails and bad addresses: strict mode
By default an email API should send whenever it can. If an address check cannot answer, the receipt should still go. That default is right for your product's own email and wrong for an agent.
So PristineSend has strict mode, which you turn on per API key, or for every agent connected through MCP with one setting. A strict email is refused instead of sent when:
- it is unfinished: no subject, an empty picture spot, or a placeholder link or picture. It answers
422 content_unfinishedand the message names each problem. - the address is bad: misspelt (
gmial.com), a throwaway domain, not deliverable, or likely to bounce. It answers422 address_rejected. The address is checked for free first; a lookup is made only when we know nothing about the address, and it uses one of your plan's monthly verifications, then prepaid credits. - the check could not run: it answers
503and you try again. A strict email is never sent unchecked.
This is the opposite of fail-open, on purpose, and only for the keys that ask for it. Details in Strict mode.
5. Make anything bulk wait for a person
One email at a time is fine to automate. A send to a whole segment is not, because the cost of a mistake is the size of the list.
In PristineSend an agent can draft a campaign with the send_bulk tool or POST /api/v1/send/bulk, and nothing is sent. The draft waits as pending_approval. An Owner or Admin of the account opens it in the app, sees the segment, the recipient count, a preview and the deliverability check, and then sends it, edits it or cancels it.
The approval cannot come from the API, so the agent cannot approve its own work. Editing the draft cancels any earlier approval, so what goes out is what a person looked at. If nobody approves it, nothing is ever sent. See Bulk send.
6. Keep the do-not-send list below the agent
"Do not email people who unsubscribed" belongs in the platform, not in the system prompt. A prompt is a request. The platform is a rule.
In PristineSend every send path checks the do-not-send list before anything goes out: campaigns, automations and API email, the agent's included. An address that bounced or reported spam is blocked for everything; an agent that tries anyway gets 403 recipient_suppressed and nothing is sent.
One thing to know: an address that unsubscribed from your marketing is blocked from campaigns and automations, but not from API email, because API email is where receipts and password resets come from. So if your agent writes marketing, have it draft a campaign (section 5) rather than send it one email at a time through the API.
Every live API email also goes through a security check before it is sent. A new kind of email, or one that names a brand you have not verified a domain for, is checked, and if it looks like it comes from someone else it is held for a quick review instead of sent: the API answers 202 with status: "held". This protects your domain from an agent that has been talked into writing someone else's email.
7. Tell the agent what happened
An agent that cannot see the result of its sends will repeat its mistakes. Give it the outcomes, in words it can act on.
The answer to the send. Map each refusal to an instruction your agent can follow:
import { PristineSend, PristineSendError } from "pristinesend"
const ps = new PristineSend(process.env.PRISTINESEND_AGENT_KEY)
// The tool your agent calls. It returns a result the agent can read,
// rather than throwing on every refusal.
export async function sendEmailTool({ to, subject, html, taskId }) {
try {
const res = await ps.emails.send({
to,
subject,
html,
// One key per task, not per call: if the agent runs the same
// task twice, the second call returns the first result.
idempotencyKey: `agent:${taskId}:${to}`,
})
return res.status === "held"
? { sent: false, held: true, id: res.id, note: "Held for a security review. Do not resend." }
: { sent: true, id: res.id }
} catch (err) {
if (!(err instanceof PristineSendError)) throw err
const advice = {
address_rejected: "The address is wrong or will bounce. Ask the person for a correct one. Do not retry it.",
content_unfinished: "The email is not finished. Fix what the message lists, then send again.",
recipient_cap_reached: "This person has had enough email from us for now. Stop and report it.",
recipient_burst: "You already sent this to them twice in 10 minutes. You may be in a loop. Stop.",
recipient_suppressed: "This person asked not to be emailed. Do not try another way.",
verification_allowance_exhausted: "No address checks left. Tell a human.",
}[err.code]
if (advice) return { sent: false, reason: err.message, advice }
throw err // the SDK has already retried 429 and 503 answers
}
}
What happened afterwards. Delivery is not the end. Subscribe a webhook to the events that matter and feed them back to the agent, or let it read them with the list_events tool:
email.bouncedandemail.complained: the address or the email was the problem;email.unsubscribed: the person said stop;email.skipped, withdetails.reason: we deliberately did not send it (suppressed,topic_opt_out,address_check,recipient_caporrecipient_burst);email.held,email.releasedandemail.blocked: what happened to an email the security check held.
Each of these is opt-in per webhook endpoint. See Webhooks.
8. Make retries safe
Agents retry. Networks fail. A send without an idempotency key, retried after a timeout, is two emails.
Send an Idempotency-Key with every request, made from the task rather than from the moment: the same task and recipient gives the same key, so the second attempt within 24 hours returns the first one's answer and sends nothing. The SDK makes one per call if you do not, which covers its own network retries but not the agent calling the tool again; that is why the example above builds its own. The MCP send_email tool takes an idempotency_key, and when the agent leaves it out, one is made from the email's content. See Idempotent requests.
The checklist
- The agent has its own key, separate from your application's.
- The key has only the permissions the agent needs. No bulk, no segments.
- You tested the agent against a
ps_test_key first. - Emails per contact is on, and the agent's key counts toward it.
- Strict mode is on for the agent's key, or for connected agents.
- Anything bulk waits for a person.
- Your agent's tool turns each refusal into an instruction it follows.
- A webhook sends bounces, complaints, unsubscribes and skips back to the agent.
- Every send carries an idempotency key made from the task.
What these guardrails do not do
Honest limits, so you can plan around them:
- They do not make bounces zero. An address can pass every check and still not exist. Strict mode refuses the likely bounces, not all of them.
- They do not give you your own IP addresses. PristineSend sends from a shared pool of IP addresses, so IP reputation is shared. Your domain's reputation is your own, and that is what these guardrails protect.
- They are not on by default for API keys. Your product's own email should keep flowing when a check cannot answer. Strict mode and the per-contact limit are choices you make for the agent's key. While the per-contact limit is on, agents connected through MCP always count toward it.
Agents are good at the work and bad at stopping. Put the stopping in the platform, keep a person on anything bulk, and give the agent the outcomes of what it sent. Then your domain survives your agent's worst afternoon.