How to let an AI agent send email safely

Give the agent its own API key that can only send, never your account or a full-access key. Then put it behind the gates you'd use for any untrusted client: it can send only from a domain you've verified, a per-workspace rate limit caps it, an idempotency key stops a retry loop from sending twice, and anything one-to-many waits for an explicit approval step.
Unitpost ·
An agent that can send email is a client that writes its own requests. That's useful for drafting a follow-up, sending a report or notifying a user. It also fails differently from a person: agents retry on errors, get stuck in loops, and sometimes read an instruction as wider than it was.
Give it a scoped key, not your account
Start here. Create a key for the agent alone, with only the capability it needs, so you can revoke it without touching anything else. A key that sends email shouldn't also be able to delete contacts or read your logs.
- One key per agent, so revoking one doesn't disrupt the others
- Only the scopes it needs: emails:send for sending, nothing more
- Never a full-access key, and never the key your application uses
What the domain gate stops
An agent can send only from a domain already verified in the workspace that owns its key. A send-only key can't add or verify a domain, and a from address on a domain you haven't verified gets a 403 (domain_not_found or domain_not_verified) however the request is worded. The worst case is unwanted mail from your own verified domain. The agent can't send as anyone else's.
Idempotency, because agents retry
Agent frameworks retry on timeouts and ambiguous errors, and an agent that can't tell whether a send went through will often try again. Send an Idempotency-Key, and a retry within 24 hours returns the original result instead of sending a second email:
await unitpost.email.send(
{
from: "Acme <hello@acme.com>",
to: "user@example.com",
subject: "Your report",
html: "<p>Attached.</p>",
},
{ idempotencyKey: `report-${runId}` },
);Derive the key from the task, not the attempt
Use an id that stays the same for the unit of work, such as a run id or a ticket id, so every retry of the same send reuses it. A random key per attempt protects nothing.
Require approval for anything one-to-many
A wrong email to one person is a mistake. The same email to a segment is an incident. The transactional API refuses a marketing send with more than one recipient (422 validation_error), so bulk marketing goes through campaigns, and a campaign goes out only at an explicit send step. Starting that send takes campaigns:send, so an agent whose key holds only emails:send can't mail your list as a campaign, whatever it decides.
Keep the audit trail
Every authenticated API request is logged, so you can answer "what did the agent send?" after the fact. That record is what makes autonomy reversible: you can grant more, review what the agent did with it, and pull it back.
