How to let an AI agent send email safely

An AI agent's email passing three gates on its way out: a scoped key, a verified domain and a person's approval

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:

cURL
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.

Frequently asked questions

What stops an agent from emailing the wrong person?

Nothing in the platform knows who the right person is. That's a prompt and application-design problem, and it's the risk you accept. The platform does block the worse outcomes: sending from a domain you don't own, mailing a segment through the transactional API, sending duplicates on retry, and mailing addresses that bounced or complained before.

Can I limit an agent to specific recipients?

Not with API scopes, which grant capabilities rather than recipients. Keep the recipient list on your side: the agent calls your own endpoint, that endpoint checks the recipient and holds the Unitpost key, and the agent never sees a credential that can send to anyone.

Should an agent use its own API key or share the app's?

Its own. A separate key lets you revoke the agent's access the moment something looks wrong without stopping your application's sending, and the request log shows exactly which sends came from the agent.

Free to start

Start sending for free

$0/ mo

  • 5,000 emails / mo — no credit card
  • Your domain with DKIM, SPF & DMARC
  • REST API, SMTP & official SDKs
  • Visual editor + code templates
  • Open & click tracking + signed webhooks
  • 10,000 contacts · automatic suppression