MailFlatDocs
Documentation/Common test cases/Sending email

Testing your own inbound email handling

Point it the other way: send real mail from a MailFlat address and check that your application handles what arrives.

How it works

Every inbox can send as well as receive. Mail leaves from the inbox address through our own MTA, DKIM-signed, so your inbound pipeline (support ticket parsing, reply-to threading, bounce handling) is exercised by a genuine message rather than a fixture.

Send from the inbox

A plain text body is enough; add HTML when the thing under test cares about it.
inbox.send(
"support@your-app.com",
subject="Order #4182 never arrived",
body="Hi, my order has not shown up yet.",
)

Then assert on your side

The sent message is also kept in the inbox with direction set to out, so you can check delivery actually succeeded.
sent = [m for m in inbox.messages() if m.direction == "out"]
assert sent[0].send_status != "failed", sent[0].send_error

Copy someone in, or don't

cc lands in the mail's headers, so every recipient sees it. bcc never does, not even in the copy the bcc'd address receives, which is exactly what makes it worth testing.
inbox.send(
"support@your-app.com",
subject="Order #4182",
body="Please look into this.",
cc=["billing@your-app.com"],
bcc=["audit@your-app.com"],
)

Wait for it to actually go out

send answers 202: accepted, not delivered. Delivery runs on a queue, so read the result back, or subscribe to the message.delivered webhook and skip polling entirely.
res = inbox.send("support@your-app.com", subject="Order #4182", body="Hi.")
inbox.wait_until_sent(res["message_id"], timeout=120) # raises if it failed

Worth knowing

Accepted is not delivered
send returns in milliseconds with 202 and a message_id; the mail is still queued at that point. A test that asserts success on the send call alone proves only that the request was accepted. Read send_status back, or listen for the message.delivered webhook. And a message still sitting at queued is not lost. The queue retries with growing delays, because a greylisting recipient can legitimately hold mail for minutes. Sent messages also use the same monthly allowance as received ones.