On this page
- Direct mail campaign plan: seven steps by API
- Pick the goal and the list for an API campaign
- Write one offer, with a code per person merged by API
- Design and proof the campaign cards in API test mode
- Split-test a direct mail campaign by API
- Code: check the list, split it and send both designs by API
- When to send and how long to count API campaign responses
- Measure the campaign by API: responses against the holdout
- Direct mail campaign questions from API senders
Direct mail campaign plan: seven steps by API
Most of the work comes before anything prints, and none of it costs anything until the live send: a test key checks, prices and proofs every card for free. What the live send costs, by format and size of run, is in direct mail cost.
Pick the goal and the list for an API campaign
Write down the one thing a response means: an order with the code, a booked appointment, a renewal. If you can’t count it in your own systems, the campaign can’t tell you anything.
Then pick who gets a card. Your own customers are the list that already knows you: last year’s buyers before a season, members before a renewal, everyone within a few miles of a new location. Narrowing and buying lists are covered in targeted direct mail. An older list should go through NCOA for people who moved, and every address gets checked before the split (step 1 in the code below). How that check compares with USPS’s own API is in USPS address verification API.
Write one offer, with a code per person merged by API
One campaign, one offer, with an end date. Give every card its own code in a merge field, such as A-10482, so a response points to a person and a group. Codes can be up to 12 characters. A short link or a QR code of that link works the same way for responses that happen online. Which other fields are worth changing per card is in personalized direct mail.
Design and proof the campaign cards in API test mode
Start from a template or your own HTML; what goes where on each side is in direct mail design. Then send the whole campaign with your test key. Every card is checked and priced, and a proof of each one shows up in the dashboard, with nothing printed or charged. When the proofs look right, POST /v1/batches/{id}/send_live sends that same batch for real without uploading anything again.
Split-test a direct mail campaign by API
A-Ada, 15% offyour next order.Code B-ADA15Design B1,800 peopleB-Not mailedHoldout400 peopleno card- Change one thing. The headline, the offer or the picture, not all three, or you won’t know which one did it.
- Split at random, after the address check and before the send, and keep the list of who went where.
- Hold out a group. A tenth of the list gets no card. Some people would have ordered anyway; the holdout shows how many, so the campaign only gets credit for the rest.
- Put the group in the code. A prefix such as
A-orB-tells you which design brought each response back.
Code: check the list, split it and send both designs by API
This checks every address, drops the undeliverable ones, splits the rest into two designs and a holdout, saves who went where, and mails each design as 6x9 postcards:
# Run once, on the day you mail. Env: MAILR_API_KEY.
# customers.csv: id (up to 10 characters), name, first_name, line1, line2, city, state, zip
# mail/a/front.html, mail/b/front.html, mail/back.html: two fronts that differ in one thing, one back,
# with {{first_name}} and {{promo_code}} in them.
import csv, os, random, requests
CAMPAIGN = "spring-2027"
API = "https://api.mailr.dev/v1"
H = {"Authorization": f"Bearer {os.environ['MAILR_API_KEY']}"}
with open("customers.csv", newline="") as f:
people = list(csv.DictReader(f))
# 1. Check every address first, so the split is made from people a card can reach.
ok = []
for start in range(0, len(people), 1000):
chunk = people[start:start + 1000]
r = requests.post(f"{API}/addresses/verify", headers=H, timeout=120,
json={"addresses": [{"name": c["name"][:40], "line1": c["line1"], "line2": c["line2"] or None,
"city": c["city"], "state": c["state"], "zip": c["zip"]} for c in chunk]})
r.raise_for_status()
for c, v in zip(chunk, r.json()["data"]):
if v["deliverability"] != "undeliverable":
ok.append({**c, "to": v["address"]}) # the corrected, USPS-standard address
# 2. Split at random: a tenth held out, the rest halved. The seed keeps a re-run's split the same.
random.Random(CAMPAIGN).shuffle(ok)
hold = len(ok) // 10
groups = {"holdout": ok[:hold], "a": ok[hold::2], "b": ok[hold + 1::2]}
with open(f"{CAMPAIGN}-groups.csv", "w", newline="") as f:
w = csv.writer(f)
w.writerow(["id", "group", "code"])
for g, members in groups.items():
w.writerows([c["id"], g, "" if g == "holdout" else f"{g.upper()}-{c['id']}"] for c in members)
# 3. Send each design to its group, in batches of up to 1,000.
back = open("mail/back.html").read()
for arm in ("a", "b"):
front = open(f"mail/{arm}/front.html").read()
members = groups[arm]
for n, start in enumerate(range(0, len(members), 1000)):
r = requests.post(f"{API}/batches", timeout=120,
headers={**H, "Idempotency-Key": f"{CAMPAIGN}-{arm}-{n}"}, # a re-run never sends a batch twice
json={"kind": "postcard", "size": "6x9", "front": front, "back": back,
"recipients": [{"to": c["to"],
"merge": {"first_name": (c["first_name"] or "Neighbor")[:14],
"promo_code": f"{arm.upper()}-{c['id']}"}}
for c in members[start:start + 1000]],
"description": f"{CAMPAIGN} design {arm.upper()}"})
r.raise_for_status()
print(arm, r.json()["id"], r.json()["count"], r.json()["price"])mlr_test_ key first: the address check is simulated, every batch is priced and proofed, and nothing prints or charges.When to send and how long to count API campaign responses
Campaign cards go by USPS Marketing Mail, which USPS puts at 3 to 10 business days and doesn’t guarantee. Anything tied to a date, such as a sale weekend or Christmas cards to clients, mails about three weeks ahead. Every card reports its statuses, and the mailed status tells you the day it was handed to USPS. Decide before you send how long after that a response still counts, and stick to it.
Measure the campaign by API: responses against the holdout
- Count codes per group. The
A-andB-codes used at checkout, from the groups file the script saved. - Count the holdout’s orders in the same window, with no code, since they had none.
- Compare rates, not totals. Responses divided by people, per group. What a design added is its rate minus the holdout’s.
- Cost per added response is what the group’s cards cost divided by the responses above the holdout’s rate.
Keep the winner for the next campaign and test one new change against it.
Direct mail campaign questions from API senders
How much does a direct mail campaign cost?
With Mailr, a 6x9 postcard is $0.89 on pay as you go, printing and postage included, and checking an address is $0.07. A campaign to 2,000 people is $1,780.00 for the cards and $140.00 to check the list first.
How long does a direct mail campaign take?
The planning takes as long as you give it. Once you send, the cards are printed and go by USPS Marketing Mail, which USPS puts at 3 to 10 business days and doesn't guarantee, so start counting responses after that.
Can I schedule a campaign for a later date?
Run the job on the day you want to mail, from a cron job, a CI schedule or by hand. Each request mails when you make it.
How big should the test groups be?
Split evenly, and big enough that a handful of responses either way wouldn't change your mind. With a small list, test one change per campaign and repeat it on the next one.
Do I need a mailing list to run a campaign?
Your own customers are the list to start with. Where else lists come from, and what each costs, is in targeted direct mail.