Reply in thread
Reply, reply-all and forward from an inbox, keep conversations threaded with In-Reply-To and References, prepare replies as drafts, and label whole threads.
Email threading depends on two headers: In-Reply-To names the message being answered, and References lists the conversation so far. MachineMail sets both for you when you use the reply endpoints, and uses them to group inbound mail into threads.
Reply
What the endpoint does:
- Recipients. For an inbound message it replies to the message’s
reply_toaddresses if present, otherwise tofrom. For one of your own sent messages it goes to that message’sto. Passtoto override. - Subject.
Re:plus the original subject, unless it already starts withRe:. Asubjectin the body is ignored. - Headers.
In-Reply-Tois the original’sMessage-ID, andReferencesis the original’s references plus that ID. - Thread. The reply joins the original’s thread, so
thread_idmatches.
The body accepts the same fields as a send except subject: text, html, to, cc, bcc, reply_to, labels, attachments and headers. See Sending.
The key needs message_reply or message_send.
Reply all
POST .../messages/{message_id}/reply-all sends to the original from and to, with the original cc copied, all minus your own inbox address.
Note
Reply-all computes to and cc from the original message and ignores to and cc in the request. You can still add bcc. To choose recipients yourself, use reply with to and cc.
Forward
POST .../messages/{message_id}/forward requires to. The subject defaults to Fwd: plus the original subject; pass subject to change it. Your text comes first, followed by a forwarded-message header (From, Date, Subject, To) and the original plain-text body.
A forward starts a new thread. The original’s attachments are not copied; pass attachments if the recipient needs them. See Attachments.
Warning
Forwarding passes untrusted content to someone else. If the original is suspicious, forward it to a human reviewer only, never to an address the message itself asked for.
How threading works
Every message you send gets a Message-ID of the form <msg_id@inbox-domain>, for example <msg_01m4fy8h340000kzb2kp66c161@machinemail.dev>.
When mail arrives, MachineMail looks at its In-Reply-To and References headers and searches the same inbox for a message with a matching Message-ID, or for one of its own msg_ IDs. If it finds one, the new message joins that thread. Otherwise it starts a new thread.
So an inbound reply to your message lands in your thread, and the message records the link:
Threads are per inbox. If two of your inboxes receive the same conversation, each has its own thread.
Threading a plain send
If you need to answer a message without the reply endpoint, for example a message you only know by its RFC Message-ID, set the headers on a normal send. MachineMail resolves the thread from them the same way:
headers is a map of extra header names to values and is passed through to the outgoing message.
Reply as a draft
To have a person review a reply before it goes out, create a draft with in_reply_to set to the MachineMail message_id you are answering. When the draft is sent it gets the right In-Reply-To and References headers and joins the thread.
Drafts do not set the subject or recipients for you, so fill in to and subject yourself. Send it with POST /v0/inboxes/{inbox_id}/drafts/{draft_id}/send, or set send_at to schedule it. Every unsent draft is listed in the dashboard at /app/drafts, where a person can send or delete it. See Drafts.
Read and label a whole thread
GET /v0/threads/{thread_id} returns the thread summary and every message in it, oldest first. The same thread is also at /v0/inboxes/{inbox_id}/threads/{thread_id}.
Thread labels are the union of the labels on its messages. PATCH /v0/threads/{thread_id} applies add_labels and remove_labels to every message in the thread, which is how you mark a whole conversation read:
Changing thread labels needs message_update. DELETE /v0/threads/{thread_id} deletes every message in the thread and needs thread_delete.