Direct mail API for developers and growth teams. Read the docs →

Direct mail campaign by API: plan it, test it, send it and count what came back

A direct mail campaign is one planned mailing: a list you choose, one offer, a date you mail and a window in which you count the responses. Run through a direct mail API, the list comes straight from your own data, every card carries a code of its own, two designs can be tested against each other and against people you don’t mail, and the whole send is a few batch requests. Below are the seven steps, with the code that checks the list, splits it and mails both designs.

On this page
  1. Direct mail campaign plan: seven steps by API
  2. Pick the goal and the list for an API campaign
  3. Write one offer, with a code per person merged by API
  4. Design and proof the campaign cards in API test mode
  5. Split-test a direct mail campaign by API
  6. Code: check the list, split it and send both designs by API
  7. When to send and how long to count API campaign responses
  8. Measure the campaign by API: responses against the holdout
  9. Direct mail campaign questions from API senders

Direct mail campaign plan: seven steps by API

1GoalOne action you can count2ListWho gets a card3OfferA code of their own4DesignFront, back, merge fields5ProofTest key, nothing charged6SendBatches of up to 1,0007MeasureCodes against the holdout
Seven steps, most of them before anything prints. The proof step costs nothing with a test key, and the same batch then goes out live without being uploaded again.

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

customers.csv 4,000 peopleHi Ada,Spring is here.Code A-ADA15Design A1,800 peopleA-Ada, 15% offyour next order.Code B-ADA15Design B1,800 peopleB-Not mailedHoldout400 peopleno card
Split at random before you send. Two designs that differ in one thing, and a tenth of the list left unmailed. The code prefix on each card tells you which group a response came from. The counts are an example.
  • 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- or B- 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"])
Run it with an 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- and B- 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.

START SENDING

Put your first postcard in the mail

Create a key, send a test to yourself, and check the proof before anything prints.

Start sending
  • Postcards, flats and folded mailers
  • A proof before anything prints
  • Free test mode: nothing prints, nothing charges
  • A status for every piece

Free price sheet

Get the price sheet by email

Every postcard, letter, mailer and print product on every plan, with postage included.

We’ll email you the price sheet. By continuing you agree to the Terms and Privacy Policy.

Download the template kit?

mailr-kit.zip · about 310 KB · 59 text files

Only HTML, JSON and Markdown files. No programs, scripts or macros, nothing that installs or runs.