API reference
Request fields, authentication, errors, and delivery semantics.
Authentication
Send the workspace API key as a Bearer token in the Authorization header. Use a test key for the simulator.
Test keys only submit simulator messages and read Test activity. Live keys submit through Amazon SES when live delivery is configured and use a verified sender domain. Use Full access for reads.
Send an Idempotency-Key header to replay an identical request safely. The key is optional and may be up to 255 characters.
The email API allows up to 120 requests per minute per source IP. API keys also share a limit of 600 requests per minute per workspace and mode.
Request
POST /api/v1/emails
curl --fail-with-body --request POST https://mailgateapi.com/api/v1/emails \
--header "Authorization: Bearer ${MAILGATE_API_KEY:?Set MAILGATE_API_KEY}" \
--header "Content-Type: application/json" \
--header "Idempotency-Key: first-test-1" \
--data '{
"from": "noreply@simulator.mailgate.test",
"to": "delivered@simulator.mailgate.test",
"subject": "My first test",
"text": "Hello from the MailGateAPI simulator."
}'
Request fields
| Field | Type | Description |
|---|---|---|
from |
string |
Sender address. Live sending requires a verified domain. |
to, cc, bcc |
string | string[] |
Recipient address or array of addresses. Maximum 50 recipients across To, Cc, and Bcc. |
reply_to |
string | string[] |
Optional reply address or array of addresses. |
subject |
string |
Subject line. |
html, text |
string |
Message body. Supply text, HTML, or both. |
scheduled_at |
string |
Optional ISO 8601 date and time in the future, up to 30 days ahead. |
attachments |
object[] |
Up to 10 files and 3 MiB decoded per message. Provide filename, base64 content and optional content_type. |
Response
202 Accepted
{
"id": "019ac981-24bd-704d-90e4-9bcd1d8d045e",
"status": "queued",
"mode": "test"
}
An accepted API request confirms receipt by the API. Use delivery events to learn what happens as the message is processed.
Other endpoints
| Endpoint | Description |
|---|---|
POST /api/v1/emails/batch |
Send a JSON array of up to 100 messages with at most 500 total recipients. |
GET /api/v1/emails |
List messages for the active workspace and key mode. |
GET /api/v1/emails/{id} |
Read the status and recipient outcomes for one message. |
POST /api/v1/emails/{id}/cancel |
Cancel a scheduled message before it is claimed for sending. |
Inbox
The Inbox API requires a Full access Live key. Configure receiving and register a verified-domain address in the dashboard.
| Endpoint | Description |
|---|---|
GET /api/v1/inbox |
List received messages for a workspace, 25 per page. |
GET /api/v1/inbox/{message} |
Read a received message, its plain-text body and attachment links. |
GET /api/v1/inbox/{message}/attachments/{attachment} |
Download an attachment with a Full access Live key and the signed URL from the message detail. The URL expires in five minutes. |
Verify a webhook
Read X-Mailgate-Timestamp and X-Mailgate-Signature from the request headers. Verify the HMAC over the timestamp, a period and the exact request body before parsing JSON. Use the displayed endpoint secret as text. This example accepts a timestamp within five minutes and uses a constant-time comparison.
GET /api/v1/inbox/{message}/attachments/{attachment}
const { createHmac, timingSafeEqual } = require('node:crypto');
function verify(rawBody, timestamp, signature, secret) {
if (!secret || !Buffer.isBuffer(rawBody)) return false;
if (!/^[0-9]{1,11}$/.test(timestamp ?? '')) return false;
if (!/^v1=[a-f0-9]{64}$/.test(signature ?? '')) return false;
if (Math.abs(Math.floor(Date.now() / 1000) - Number(timestamp)) > 300) return false;
const expected = createHmac('sha256', secret)
.update(timestamp + '.')
.update(rawBody)
.digest();
return timingSafeEqual(expected, Buffer.from(signature.slice(3), 'hex'));
}
Deduplicate by the event ID in X-Mailgate-Event-Id. Return 2xx after recording the event. Failed requests are retried after 1 minute, 5 minutes, 30 minutes, 2 hours and 12 hours.
Submit mail over SMTP
SMTP submission depends on your deployment’s SMTP listener and live delivery being enabled.
Use the hostname and port shown in your workspace, STARTTLS with certificate verification, username mailgate and a Live key with Sending access or Full access as the password. Use a verified envelope sender that matches the From header.
A submission supports up to 50 recipients, 5 MiB of MIME data and 1 MiB of decoded text and HTML combined. A message can include up to 10 file attachments totaling 3 MiB decoded. Inline Content-ID parts are unsupported.
GET /api/v1/inbox/{message}/attachments/{attachment}
import os
import smtplib
import ssl
from email.message import EmailMessage
from email.utils import make_msgid
message = EmailMessage()
message["From"] = os.environ["MAILGATE_SMTP_FROM"]
message["To"] = os.environ["MAILGATE_SMTP_TO"]
message["Message-ID"] = make_msgid()
message["Subject"] = "SMTP submission"
message.set_content("Hello from MailGateAPI.")
with smtplib.SMTP(
os.environ["MAILGATE_SMTP_HOST"],
int(os.environ.get("MAILGATE_SMTP_PORT", "587")),
timeout=20,
) as smtp:
smtp.starttls(context=ssl.create_default_context())
smtp.login("mailgate", os.environ["MAILGATE_SMTP_KEY"])
smtp.send_message(message)
Errors
| Status | Meaning |
|---|---|
401 |
The request is missing a valid API key. |
403 |
The key lacks permission for this action or sending identity. |
404 |
The message is unavailable to this workspace and key mode. |
409 |
The idempotency key was used with a different request or the message cannot be canceled. |
413 |
The JSON request body exceeds 6 MiB. |
415 |
Send a request body with Content-Type application/json. |
422 |
The request could not be validated. |
429 |
The request exceeds an applicable sending limit. |
503 |
Delivery for the requested mode is temporarily unavailable. |