Send Your First Email
Set up an email identity, send an email, and enable AI auto-responses in under 5 minutes.
Create an email identity, send a message, and optionally connect an AI agent for automatic replies.
Create an email identity
Provision an email address that your agents and API can send from.
curl -X POST https://api.trunx.ai/api/email/identities \
-H "Authorization: Bearer $TRUNX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"localPart": "support",
"displayName": "Support Team"
}'const response = await fetch("https://api.trunx.ai/api/email/identities", {
method: "POST",
headers: {
Authorization: "Bearer tk_live_...",
"Content-Type": "application/json",
},
body: JSON.stringify({
localPart: "support",
displayName: "Support Team",
}),
});
const identity = await response.json();
console.log(identity.address); // support@agentmail.toimport requests
response = requests.post(
"https://api.trunx.ai/api/email/identities",
headers={"Authorization": "Bearer tk_live_..."},
json={
"localPart": "support",
"displayName": "Support Team",
},
)
identity = response.json()
print(identity["address"]) # support@agentmail.toYou can also create identities from the Email dashboard page using the "New Identity" button.
Send an email
Use the identity ID from the previous step to send an email.
curl -X POST https://api.trunx.ai/api/email/identities/$IDENTITY_ID/send \
-H "Authorization: Bearer $TRUNX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "customer@example.com",
"subject": "Welcome to our service",
"body": "Hi! Thanks for signing up. Let us know if you have any questions."
}'const result = await fetch(`https://api.trunx.ai/api/email/identities/${identityId}/send`, {
method: "POST",
headers: {
Authorization: "Bearer tk_live_...",
"Content-Type": "application/json",
},
body: JSON.stringify({
to: "customer@example.com",
subject: "Welcome to our service",
body: "Hi! Thanks for signing up. Let us know if you have any questions.",
}),
}).then((r) => r.json());
console.log(result.threadId); // thread_abc123result = requests.post(
f"https://api.trunx.ai/api/email/identities/{identity_id}/send",
headers={"Authorization": "Bearer tk_live_..."},
json={
"to": "customer@example.com",
"subject": "Welcome to our service",
"body": "Hi! Thanks for signing up. Let us know if you have any questions.",
},
).json()
print(result["threadId"]) # thread_abc123Response:
{
"messageId": "msg_abc123",
"threadId": "thread_xyz789"
}Receive inbound email
Register a webhook for the email.received event to get notified when someone replies.
curl -X POST https://api.trunx.ai/api/webhooks \
-H "Authorization: Bearer $TRUNX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://your-app.com/webhooks/email",
"events": ["email.received"]
}'When an email arrives, Trunx sends a POST to your endpoint:
{
"event": "email.received",
"data": {
"identityId": "a1b2c3d4-...",
"from": "customer@example.com",
"to": "support@agentmail.to",
"subject": "Re: Welcome to our service",
"threadId": "thread_xyz789",
"messageId": "msg_def456"
}
}Enable AI auto-responses (optional)
Assign an agent to your email identity. When an inbound email arrives, the agent automatically generates and sends a reply using its textModel and cross-channel context.
# Assign an existing agent to the identity
curl -X PATCH https://api.trunx.ai/api/email/identities/$IDENTITY_ID \
-H "Authorization: Bearer $TRUNX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"agentId": "your-agent-id"}'The agent uses the same hub-and-spoke pattern as SMS:
- Enriches its system prompt with SMS history, call transcripts, and knowledge base results based on
contextSources - Generates a reply using its configured
textModel - Sends the reply to the same email thread
The agent must have a textModel configured (e.g. claude-haiku-4-5-20251001 or gpt-4o). Agents without a text model will not respond to emails.
You can also assign agents from the Email dashboard page using the agent dropdown next to each identity.