Reply to an email
Send a reply that stays in the same thread
Replying to a message keeps the conversation threaded — the sender's mail client groups your reply with the original. Loomal handles the headers server-side; you pass the message ID you're replying to. This is the Buyer side.
Before you start
- A project at console.loomal.ai with Mail turned on.
- A
messageIdfrom a received email — fetch one withloomal.mail.listMessages({ labels: "unread" })(see Receive emails).
Send a reply
text is required (plain-text fallback). html is optional and rendered by mail clients that support it. The first argument is always the messageId of the email you're replying to — Loomal looks it up, sets the In-Reply-To and References headers, prefixes the subject with Re:, and routes the reply to the original sender.
import { Loomal } from "@loomal/sdk";
const loomal = new Loomal({ apiKey: process.env.LOOMAL_API_KEY! });
const reply = await loomal.mail.reply("<abc123@mailgent.dev>", {
text: "Thanks — calendar link below.",
html: '<p>Thanks — <a href="https://cal.com/agent">book a time here</a>.</p>',
});
console.log(reply.messageId, reply.threadId);import os
from loomal import Loomal
loomal = Loomal(api_key=os.environ["LOOMAL_API_KEY"])
reply = loomal.mail.reply(
"<abc123@mailgent.dev>",
text="Thanks — calendar link below.",
html='<p>Thanks — <a href="https://cal.com/agent">book a time here</a>.</p>',
)
print(reply.message_id, reply.thread_id)The returned threadId matches the original message, so subsequent replies in the same conversation will appear in the same thread when you query with loomal.mail.getThread(threadId).