Sending
Templates and variables
Store your emails as versioned templates with Liquid variables, and send them by alias.
NeedsAny accountTest keys work as soon as you sign up. Nothing is delivered.
A template holds a subject, HTML and text with Liquid variables such as {{ order_no }}. You edit a draft, publish it as a new version, and sending always uses the published version, so editing never changes what's going out until you publish.
Create and publish
await pm.templates.create({
name: "Receipt",
alias: "receipt",
subject: "Your receipt #{{ order_no }}",
html: "<p>Hi {{ name | default: 'there' }}, your total is {{ total }}.</p>",
variables: [
{ name: "order_no", required: true },
{ name: "total", required: true },
{ name: "name" },
],
});
await pm.templates.publish("receipt");Send with a template
await pm.emails.send({
from: "Acme Store <hello@acme.ng>",
to: "ada@example.com",
template: { id: "receipt", variables: { order_no: "1042", total: "₦12,500", name: "Ada" } },
});curl -X POST https://api.padimail.app/v1/emails \
-H "Authorization: Bearer $PADIMAIL_API_KEY" -H "Content-Type: application/json" \
-d '{"from": "Acme Store <hello@acme.ng>", "to": "ada@example.com", "template": {"id": "receipt", "variables": {"order_no": "1042", "total": "₦12,500"}}}'template.id takes the template's ID or its alias. A template can't be combined with html or text. If a required variable is missing, the send fails with 400 template_variables_missing.
Preview
const preview = await pm.templates.render("receipt", { variables: { order_no: "1042" } });
console.log(preview.missing_variables); // ["total"]Versions
Every publish makes version N+1. GET /v1/templates/{id}/versions lists them, and PATCH /v1/templates/{id} with restore_version copies an old version into the draft.
Was this page helpful?