MAILGENT
For Buyers

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. Mailgent 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.mailgent.dev with Mail turned on.
  • A messageId from a received email — fetch one with mailgent.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 — Mailgent looks it up, sets the In-Reply-To and References headers, prefixes the subject with Re:, and routes the reply to the original sender.

reply.ts
import { Mailgent } from "@mailgent/sdk";

const mailgent = new Mailgent({ apiKey: process.env.MAILGENT_API_KEY! });

const reply = await mailgent.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);
reply.py
import os
from mailgent import Mailgent

mailgent = Mailgent(api_key=os.environ["MAILGENT_API_KEY"])

reply = mailgent.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 mailgent.mail.getThread(threadId).

What's next

On this page