Send from a client · Published 2026-09-22 · Updated 2026-09-29 · AgentiSend
Send email from a Replit app
To send email from a Replit app, verify a domain, create a key with a budget, store it as a project secret, and ask Replit to add a server-side send.
To send email from a Replit app, verify a domain, create a key with sending_access and a budget, store it as a project secret, and ask Replit to add a server-side send that calls the API. Replit has no AgentiSend connector. This page does not describe one, and a catalog listing for some other email vendor is not a substitute.
One file, whichever runtime the server uses
The sample is a single Hono route. The SDK inside it is plain fetch with no Node built-ins, so the same file runs on Node, Bun and Deno without edits, and this page does not need to know which of those the Replit app's server is on. The file is run by the test suite against a local AgentiSend server.
Secrets, not source
The key goes in a project secret named AGENTISEND_API_KEY. With no argument, the SDK's constructor reads it from the environment, so the code never contains it. MAIL_FROM is a second secret: a From address on the domain you verified. Both are read by server code only; a file the browser loads should reference neither.
Before either secret goes in, the key needs its ceiling. Create it with POST /api-keys and permission sending_access, then set the budget and period with PATCH /limits/keys/{id}.
The prompt to paste
Add a POST route to this app's server that sends one email through AgentiSend. Follow the Hono sample at https://agentisend.com/docs/guides/hono and the contract at https://agentisend.com/openapi.json, and install the npm package agentisend. There is no AgentiSend connector to enable, and another vendor's listing is not a substitute. Take the key from the secret AGENTISEND_API_KEY and the sender from MAIL_FROM, on the server only. Use an idempotency key derived from the recipient. On a refusal, return code and fix to the caller and stop retrying when retryable is false. Before wiring the route to anything, call POST /emails/preflight with the same body and show me what it returns.The code that prompt should produce
/**
* Hono — one POST route that sends a transactional email.
*
* Hono runs on Workers, Deno, Bun and Node, and the AgentiSend SDK is plain
* fetch with no Node built-ins, so this file is the same on all of them.
*/
import { Hono } from 'hono';
import { AgentiSend, AgentiSendError } from 'agentisend';
const agentisend = new AgentiSend();
function mailFrom(): string {
const from = process.env.MAIL_FROM;
if (!from) throw new Error('Set MAIL_FROM to an address on a domain you have verified.');
return from;
}
export const app = new Hono();
app.post('/send', async (c) => {
const { email, subject, body } = await c.req.json<{
email?: string;
subject?: string;
body?: string;
}>();
if (!email) return c.json({ error: 'email is required' }, 400);
try {
const { id } = await agentisend.emails.send(
{
from: mailFrom(),
to: email,
subject: subject ?? 'Your receipt',
text: body ?? 'Thanks — your receipt is attached to your account.',
},
{ idempotencyKey: `receipt/${email}` },
);
return c.json({ id });
} catch (err) {
if (err instanceof AgentiSendError) {
// `fix` names the endpoint that repairs the call, so a client can act on
// the failure without a human reading prose.
return c.json({ code: err.code, fix: err.fix }, 502);
}
throw err;
}
});
export default app;Check it without sending
POST /emails/preflight takes the same body as POST /emails and runs every gate a send runs: domain, sandbox, trust, suppression, budget, loop guard and content. It creates no message. When ok is false, error carries the same code, message and fix the real send would have returned, so one call from the running app shows whether the secrets, the sender and the ceiling are right before anyone is mailed.
The same limits from every client
Budgets, loop detection, approvals and the kill switch behave identically whichever client holds the key, so they are not repeated here. The guardrails checklist maps each item people are told to hand-write onto the request that already enforces it, and Email for AI agents names every control with its endpoint.
Next
- Email for AI agents names every control and the request that calls it.
- Email guardrails maps the usual checklist onto these same fields.
- Send email with Hono is the guide this sample is taken from.