Use case: inbound email
Inbound email API: every message as JSON, or POSTed to your webhook
Point mail at an address on agent.restapi.email and stop thinking about MX records, mail servers and MIME parsing. Read each message over REST, or receive it at an HTTPS endpoint with an HMAC signature and retries.
Email as a trigger
Forwarded documents
Forward invoices, receipts or reports to an address and parse subject, text and HTML in your own code.
Instructions to an agent
Let people email your agent. Each message reaches your endpoint as JSON, with the From header and the envelope sender kept apart.
Replies and confirmations
Collect replies to a workflow, or confirmations from a third-party system, without running a mailbox for them.
Email to webhook
Each message is POSTed as soon as it is stored. Verify the signature over the raw body, answer 2xx within five seconds, and you are done; a failed attempt is retried after 30 seconds, 5 minutes, 30 minutes and 2 hours.
POST /hooks/email
Content-Type: application/json
X-Restapi-Email-Event: message.received
X-Restapi-Email-Signature: sha256=<hex HMAC-SHA256 of the raw body>
{ "event": "message.received",
"message": { "id": "...", "from": "sender@example.com",
"envelope_from": "bounce+abc123@mail.example.com",
"to": "my-agent@agent.restapi.email", "subject": "Example",
"text_content": "...", "html_content": "...",
"headers": { "subject": "Example" }, "status": "received",
"received_at": "2026-11-19T12:00:00.000Z",
"extracted": { "codes": ["582014"],
"links": ["https://example.com/verify?token=abc"] } } }import crypto from 'node:crypto';
// rawBody: the exact bytes received, before JSON.parse
function isValidWebhook(rawBody, signature, secret) {
const expected = 'sha256=' +
crypto.createHmac('sha256', secret).update(rawBody).digest('hex');
return typeof signature === 'string' &&
signature.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
}
// Express: app.post('/hooks/email', express.raw({ type: 'application/json', limit: '5mb' }), (req, res) => {
// if (!isValidWebhook(req.body, req.get('X-Restapi-Email-Signature'), SECRET))
// return res.sendStatus(401);
// const { message } = JSON.parse(req.body);
// res.sendStatus(204);
// });import hashlib
import hmac
# raw_body: the exact bytes received, before json.loads
def is_valid_webhook(raw_body: bytes, signature: str, secret: str) -> bool:
expected = "sha256=" + hmac.new(
secret.encode(), raw_body, hashlib.sha256
).hexdigest()
return hmac.compare_digest(signature or "", expected)
# Flask:
# @app.post("/hooks/email")
# def hook():
# if not is_valid_webhook(request.get_data(),
# request.headers.get("X-Restapi-Email-Signature"), SECRET):
# abort(401)
# message = request.get_json()["message"]
# return "", 204Or read it over REST
List with cursor pagination and full-text search, fetch one message with its raw MIME, and delete it when you are done.
curl "https://api.restapi.email/api/v1/emails/my-agent@agent.restapi.email/messages/MESSAGE_ID" \
-H "X-API-Key: sk_agent_..."
{ "email": { "id": "...", "from": "noreply@example.com",
"envelope_from": "bounce+abc123@mail.example.com",
"to": "my-agent@agent.restapi.email", "subject": "Your code is 482913",
"text_content": "...", "html_content": "...", "headers": { "...": "..." },
"raw_content": "...", "status": "received",
"received_at": "2026-11-19T09:14:02.000Z",
"extracted": { "codes": ["482913"],
"links": ["https://example.com/verify?token=..."] } } }Testing your app’s email in CI
Use a real address in an end-to-end test, wait for the verification or password-reset email your app sends, and assert on it. The long-poll replaces sleep-and-retry loops with one request.
// Playwright / Vitest: assert on the email your app sends
const API = 'https://api.restapi.email';
const INBOX = 'ci-signup@agent.restapi.email';
const headers = { 'X-API-Key': process.env.RESTAPI_EMAIL_KEY };
const newest = await fetch(`${API}/api/v1/emails/${INBOX}/messages?limit=1`, { headers })
.then((r) => r.json());
const since = newest.emails[0]?.id ?? new Date().toISOString();
await page.fill('#email', INBOX);
await page.click('text=Sign up');
const { emails } = await fetch(
`${API}/api/v1/emails/${INBOX}/messages?since=${since}&wait=25`, { headers }
).then((r) => r.json());
expect(emails.length).toBeGreaterThan(0);
expect(emails[0].subject).toContain('Confirm your account');Questions
What does the webhook payload contain?
The event name and the message: id, from, envelope_from, to, subject, text_content, html_content, headers, status, received_at and extracted codes and links. Raw MIME is not included; fetch the message for that.
What is the difference between from and envelope_from?
from is the address in the From header, the sender a person means. envelope_from is the SMTP envelope sender, usually a bounce address; use it for bounce handling, not for display.
What happens if my endpoint is down?
The delivery is retried after 30 seconds, 5 minutes, 30 minutes and 2 hours, five attempts in all, and every attempt is recorded in the delivery log. The message also stays readable over the API for 30 days.
What happens when I reach my plan limit?
Mail over your monthly or storage allowance is refused at delivery, so the sender is told. There are no overage charges.
Full details: webhooks in the docs.
Turn inbound email into JSON
Create an account, pick a plan, and read your first message with one authenticated request.
Receive-only. Paid plans, by card, cancel any time.