Getting Started
Receive Emails
Read incoming emails sent to your agent
When someone sends an email to your agent's address (e.g., salesagent-x8k2m@mailgent.dev), Mailgent receives it, parses it, and makes it available via the API.
List Unread Messages
curl https://api.mailgent.dev/v0/messages?labels=unread \
-H "Authorization: Bearer mgent-your-api-key"Response
{
"messages": [
{
"messageId": "<abc123@gmail.com>",
"threadId": "thd_f8e2a1c4d7b90e3f",
"from": ["customer@gmail.com"],
"to": ["salesagent-x8k2m@mailgent.dev"],
"subject": "Question about pricing",
"text": "Hi, I'd like to know about your enterprise plan.",
"extractedText": "Hi, I'd like to know about your enterprise plan.",
"labels": ["received", "unread"],
"createdAt": "2026-03-28T12:00:00.000Z"
}
],
"count": 1
}Extracted Text
The extractedText field contains the reply-stripped body — quoted history and signatures are removed. This is ideal for feeding into an LLM.
| Field | Content |
|---|---|
text | Full plain text body |
extractedText | Reply text only (no quoted history) |
Mark as Read
After processing a message, mark it as read:
curl -X PATCH https://api.mailgent.dev/v0/messages/%3Cabc123%40gmail.com%3E \
-H "Authorization: Bearer mgent-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"addLabels": ["read"],
"removeLabels": ["unread"]
}'Reply to an Email
curl -X POST https://api.mailgent.dev/v0/messages/%3Cabc123%40gmail.com%3E/reply \
-H "Authorization: Bearer mgent-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"text": "Thanks for reaching out! Our enterprise plan starts at..."
}'The reply is automatically threaded — same threadId, correct In-Reply-To and References headers.
Using MCP
With MCP, the agent flow looks like:
1. Agent calls mail.list_messages(labels: "unread")
2. Gets new email from customer
3. Processes with LLM
4. Calls mail.reply(messageId: "...", text: "...")
5. Calls mail.update_labels(messageId: "...", addLabels: ["read"], removeLabels: ["unread"])