Airtable direct mail: mail a postcard from an automation
Airtable direct mail with Mailr is one automation: when a record matches your conditions, a Run a script action sends the address to Mailr with fetch(), Mailr prints and mails the postcard, and the script writes the postcard id back to the record.
What to mail from Airtable
| When this happens | Mail this |
|---|---|
| When a record matches conditions (Status is "Mail thank-you") | A thank-you postcard with a promo code. (First-order thank you) |
| When a record enters a view ("New customers") | A founder welcome letter, mailed flat. (Welcome letter) |
| At a scheduled time (Mondays), for a "Lapsed, not mailed" view | One batch of win-back cards, up to 1,000 per request. (Win-back) |
Set it up
- Set up the table. Add fields for Name, Address, Address 2, City, State (two letters), ZIP and First name, plus Mailr ID and Mail status for the script to fill. Make ZIP a single line text field so leading zeros survive.
- Create the automation. Pick the trigger "When a record matches conditions" (for example, Status is Mail thank-you), then add the action "Run a script".
- Add the input and the secret. In the script's sidebar, add an input variable named recordId set to the Airtable record ID from the trigger. Add a secret named MAILR_API_KEY with your Mailr test key; the script reads it with input.secret().
- Test, then turn it on. Paste the script, click Test to run it on a matching record (test pieces are free and never print), and turn the automation on. To go live, change the secret's value to your mlr_live_ key.
The Run a script action
// Trigger: When a record matches conditions. Input variable: recordId. Secret: MAILR_API_KEY.
const { recordId } = input.config();
const table = base.getTable("Customers");
const record = await table.selectRecordAsync(recordId);
if (!record) throw new Error(`Record ${recordId} not found`);
const cell = (field) => record.getCellValueAsString(field).trim();
const res = await fetch("https://api.mailr.dev/v1/postcards", {
method: "POST",
headers: {
Authorization: `Bearer ${input.secret("MAILR_API_KEY")}`,
"Content-Type": "application/json",
"Idempotency-Key": `airtable-thank-you-${recordId}`,
},
body: JSON.stringify({
size: "6x9",
template: "tmpl_thank_you",
to: {
name: cell("Name").slice(0, 40),
line1: cell("Address"),
line2: cell("Address 2"),
city: cell("City"),
state: cell("State"),
zip: cell("ZIP"),
},
from: { name: "Acme Outdoor", line1: "1 Example Way", city: "Phoenix", state: "AZ", zip: "85004" },
merge: { first_name: cell("First name").slice(0, 14), promo_code: "THANKS15" },
}),
});
const piece = await res.json();
if (!res.ok) throw new Error(`Mailr ${res.status}: ${piece.error?.message} (${piece.error?.field ?? "no field"})`);
await table.updateRecordAsync(recordId, { "Mailr ID": piece.id, "Mail status": piece.status });
output.set("postcardId", piece.id);- Run a script works on every Airtable plan except Team trials and the Student plan. The Free plan allows 100 automation runs per workspace a month; Team allows 25,000.
- Each run gets 50 fetch requests, and a fetch times out after 30 seconds. Scripts have a 30-second limit that Airtable has temporarily raised to 120. For more than a few records at once, use the batch: one request for up to 1,000.
- Secrets read with input.secret() are redacted from console output, and only people who can access a script's secrets can edit it.
- Make ZIP a single line text field. A number field turns 02134 into 2134, and Mailr rejects anything but a 5-digit or ZIP+4 code.
- Mailr has no webhooks yet, so status doesn't flow back on its own. A scheduled script can refresh Mail status with GET /v1/postcards/{id}, up to 50 records per run.
What it costs
Each live piece is paid from your Mailr balance, printing and postage included: a 4x6 postcard is $0.85, a 6x9 $0.89 and an 8.5x11 letter $0.95 on pay as you go, less on a plan. Test pieces are free. All prices.
Templates that fit: First-order thank you (6x9), Welcome letter (8.5x11), Win-back (6x11).
Questions
Is there a Mailr extension in the Airtable Marketplace?
No. Mailr has no Airtable extension or app. The automation calls Mailr's REST API with fetch(), which Airtable allows in automation scripts.
Can a button send the postcard instead?
Yes. Use an interface button as the automation's trigger and the same script. The Idempotency-Key stops a double click from mailing twice within 24 hours, and the Mailr ID field shows it was sent.
Why did the whole batch fail?
Batches are all or nothing: Mailr checks every address and merge field before anything is made and returns the first problem with its field, like recipients[12].to.zip (the 13th record in the view). Fix that record and run it again.
Can I mail letters instead of postcards?
Yes. Send to /v1/flats with size 8.5x11 and a flat template such as tmpl_welcome (first_name, company, founder_name). In a batch, set kind to "flat".