API reference
Cancel a scheduled email
A message sent with scheduledAt reads scheduled until it dispatches, and can be cancelled up to that moment. A cancelled send is never charged against your quota, because quota is charged at dispatch.
Why use this
409 here means it genuinely went.For example
A reminder is scheduled for the morning a trial ends. The customer upgrades the night before, and your upgrade handler cancels the reminder by id.
Example
import { YourMail } from "yourmail";
const yourmail = new YourMail(process.env.YOURMAIL_API_KEY!);
const { id } = await yourmail.send({
from: "hello@mail.acme.com",
to: "alice@example.com",
subject: "Your trial ends tomorrow",
html: "<p>...</p>",
scheduledAt: "2026-09-10T09:00:00Z",
});
// Alice upgraded overnight — don't send it.
const { canceled } = await yourmail.cancel(id); // truecurl -X DELETE https://api.yourmail.dev/v1/emails/EMAIL_ID \
-H "Authorization: Bearer YOUR_API_KEY"Response
// 200 OK
{ "id": "jn7abc...", "canceled": true }
// 409 Conflict — it has already gone
{
"error": {
"type": "validation_error",
"message": "This email is sent and can no longer be cancelled. Only a scheduled send that has not dispatched can be.",
"docs_url": "https://yourmail.dev/docs/errors#validation_error"
}
}The message's status becomes canceled — its own value rather than a reuse of failed, which the dashboard explains to a customer as a delivery problem. No webhook fires for a cancellation. The SDK does not retry a 409: "it has already gone" is not an ambiguous failure.
Errors
See Errors for the full error shape.
authentication_errorThe API key is missing, malformed or revoked
authentication_errorThe key is send-only. Cancelling mail is not sending it, so a key made to be pasted into an agent cannot do it
not_foundNo email with that id on this account
validation_errorThe message is not scheduled — it has dispatched, failed, or was already cancelled