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

Personalized direct mail: what to personalize, with API examples

Personalized direct mail prints different text on each piece from your own data: the person’s name, what they bought, a code of their own, the place or date that matters to them. With a direct mail API, the design carries merge tags like {{first_name}}, and each recipient’s values fill them before the piece prints. The fields worth using are the ones that show you know the customer and make the next step easy. Anything private stays off a postcard, because it has no envelope.

On this page
  1. What to personalize on direct mail with an API
  2. Personalized direct mail examples from API senders
  3. Length limits and fallbacks for API merge fields
  4. What to keep off a personalized postcard sent by API
  5. How to send personalized mail with an API
  6. Personalized direct mail questions from API senders

What to personalize on direct mail with an API

Start from what you already know about each person, then pick the few fields that change the message. A name alone is polite. A name plus the product they bought plus a code they can use is a reason to come back. Size, timing and cost for the cards themselves are in postcard marketing. A holiday card often needs only the name; what else it can carry by Marketing Mail is in business Christmas cards.

Hi Ada,Still loving the Trail Pack 30L?15% off with PEAK15acme.co/r/22first_namelast_productpromo_codereview_url
One design, four fields that change. The name, the product, the code and the link come from each customer’s record; everything else is the same on every card.
  • The name. First name in the greeting, full name in the address block. It’s the field you’ll have most often and the one most often missing, so plan a fallback.
  • What they did. The last product, the job you finished, the event they came to. It turns a generic card into one about them.
  • A code or link of their own. A promo code or short link per person tells you who acted on the card when it comes back through your checkout or analytics. A QR code per person does the same for people who’d rather scan, and a gift card claim link works the same way when the card says thank you.
  • A place or a date. The nearest store, the street where the work was done, the renewal date, the event date. A date can also decide when the card goes out, as with customer birthday cards.
  • Who it’s from. A founder, a trainer, a pastor. A real name signs it, and a handwriting-style font makes the signature look like one.

Personalized direct mail examples from API senders

These come from the industry pages on this site, each built on a moment the business already records: The full set, with formats and prices, is in direct mail examples. A one-use coupon code per household is in coupon mailers.

BusinessMomentWhat changes per card
Online storeNo order in 60 daysName, last product, offer code
Auto repair shopA declined repairThe declined job, a booking QR code
Groomer or kennelFour months without a bookingThe pet’s name
Real estate agentA listing sellsThe sold address, the agent’s photo
ChurchA first giftThe fund it went to, never the amount
RooferA hail stormThe storm date
GymLast session in a packageThe trainer’s name and signature

Length limits and fallbacks for API merge fields

Every template has a fixed set of merge fields, each with a maximum length so the text fits the layout. A request that leaves one out, or sends one that’s too long, is rejected before anything prints. These are the limits on Mailr’s templates:

FieldMost characters
first_name14
promo_code12
last_product22
product_name22
company24
founder_name16
event_name28
event_date24
review_url28
cart_url28

In your own HTML design you can name fields whatever you like, up to 200 characters each. Either way, decide the fallbacks in your code before you send: “Neighbor” for a missing first name, “your last order” for a missing product. Rows whose values are too long are better fixed by hand than cut off in the middle of a word. Setting up that HTML is covered in direct mail design.

first_namepromo_code
AdaPEAK15
(empty)PEAK15
first_name or "Neighbor"Hi Neighbor,Code PEAK15
Fill the gaps before you send. A template rejects a missing field, so your code supplies a fallback, like “Neighbor” for a row with no first name.

What to keep off a personalized postcard sent by API

Postcards and flats mail without an envelope, so anyone who handles one can read it. Keep these off:

  • Amounts. What someone gave, owes or spent. The nonprofit and church pages name the fund a gift went to, never the amount.
  • Bills and past-due notices. USPS Marketing Mail can’t carry bills or statements of account, so those go another way. The class’s other rules are in USPS Marketing Mail.
  • Health, account and ID numbers. Anything you wouldn’t put on the outside of an envelope.

How to send personalized mail with an API

One request per piece, or a batch of up to 1,000 with the design once and each person’s values in merge. This script applies the fallbacks, sets aside rows that are too long, and sends the rest as 6x11 win-back postcards:

# customers.csv: one row per customer, from your store, CRM or warehouse.
# Columns: id, name, first_name, line1, line2, city, state, zip, last_product, promo_code
import csv, os, requests

LIMITS = {"first_name": 14, "last_product": 22, "promo_code": 12}  # tmpl_winback's fields

def merge_for(c):
    values = {
        "first_name": c["first_name"].strip() or "Neighbor",          # fallback when the name is missing
        "last_product": c["last_product"].strip() or "your last order",
        "promo_code": c["promo_code"].strip() or "PEAK15",
    }
    too_long = [k for k, v in values.items() if len(v) > LIMITS[k]]
    return values, too_long

send, review = [], []
with open("customers.csv", newline="") as f:
    for c in csv.DictReader(f):
        values, too_long = merge_for(c)
        if too_long:  # don't cut a product name mid-word: fix these by hand
            review.append({**c, "too_long": ",".join(too_long)})
            continue
        send.append({"to": {"name": c["name"][:40], "line1": c["line1"], "line2": c["line2"] or None,
                            "city": c["city"], "state": c["state"], "zip": c["zip"]},
                     "merge": values})

print(len(send), "to mail,", len(review), "to review")
for n, start in enumerate(range(0, len(send), 1000)):
    resp = requests.post(
        "https://api.mailr.dev/v1/batches",
        headers={"Authorization": f"Bearer {os.environ['MAILR_API_KEY']}",
                 "Idempotency-Key": f"winback-2026-11-{n}"},
        json={"kind": "postcard", "size": "6x11", "template": "tmpl_winback",
              "recipients": send[start:start + 1000], "description": "November win-back"},
        timeout=60,
    )
    resp.raise_for_status()
    print(resp.json()["id"], resp.json()["count"], resp.json()["price"])
Run it with an mlr_test_ key first and open a few proofs, including the longest names and a fallback row. Test pieces never print or charge. The same steps for a whole spreadsheet are in the variable data printing guide.

Personalized direct mail questions from API senders

What is personalized direct mail?

Mail where each piece carries text from the recipient's own record: their name, what they bought, a code of their own, the store nearest them. The design is the same for everyone; the values change per piece.

Is personalized direct mail the same as variable data printing?

It's the marketing side of the same thing. Variable data printing is how the printer changes text from piece to piece; personalization is deciding which of your data to print.

Does it cost more than mailing the same card to everyone?

Not with Mailr: a personalized card is the same price as a plain one, for example $0.89 for a 6x9 on pay as you go, printing and postage included.

What happens if a field is too long?

The request is rejected before anything prints, with an error naming the field and its limit. Check lengths in your own code first, as in the script above.

Can each card have a different image?

Yes, with your own HTML design: put a merge tag in the image's address, for example <img src="{{photo}}">, and send each recipient's image link as a merge value.

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.