Skip to content

Sending emails

Most integrations with email only send. Say your training system should email a certificate when a trainee passes. Someone designs the template in the app and sets it to active, and then your code does this:

  1. Find the template’s id once and keep it.
  2. Read its data structure while you build the integration, to see which values it expects.
  3. Send it with the trainee’s address, those values and the certificate as an attachment.
  4. Read sendings in the answer and act on any entry that says failed.

To send a form or an interactive document, use their own endpoints, which put the link into the message for you: Send a form’s link and Send an interactive document’s link.

The overview explains sending requests and lists, and the errors page the errors every endpoint can answer. Authentication explains how keys work.

POST/v1/email_templates/{id}/send

Fills the template with your data and sends it. Each recipient gets a message of their own, so recipients don’t see each other. Addresses in cc are visible, because they are copied into every message. The email goes out through your organization’s email integration: the default one, or the only active one.

Key permission: send_email

Headers: X-Api-Key, X-Api-Secret, Content-Type: application/json

Path parameters: id, the email template’s identifier.

Body field Type Required Rules
recipients array of strings Yes At least one, each a valid email address. Each gets their own message.
language object No A language source; the organization’s by default. The version in that language goes out, or the default one when the template has none.
data object No The values the template reads. Nesting and lists are fine. A top-level key must be letters, digits and underscores, not starting with a digit. Others are ignored. Only what the template reads is kept with the sending’s record.
attachments array of objects No At most 20, and at most 25 MB together.
attachments[].filename string Yes Not blank, at most 255 characters.
attachments[].content string Yes The file as plain base64, with no data: prefix. Line breaks are fine, and anything that doesn’t decode answers 422. Not blank, at most 25 MB of decoded data.
attachments[].mimetype string Yes Such as application/pdf. It’s recorded with the sending. Not blank, at most 127 characters.
cc array of strings No Valid addresses, copied into every recipient’s message.
replyTo string or null No A valid address for replies.

Every entry of recipients counts as one email towards your plan. Addresses in cc don’t. Only messages that went out are counted, and each has its own row under Sent emails, failed ones included. A value you don’t send leaves a gap in the message rather than an error, so check the data structure first.

The body can print the finished subject line as {{ subject }}. That name is taken in the body, so a subject key in data only reaches the subject line. A subject that grows past 255 characters once it’s filled in is sent whole, and the sending’s record keeps the first 255.

If at least one message went out, the answer is 200 and says how each one fared. Check every entry: a 200 can contain failures. To retry, send again to the failed addresses only.

Response field Type Meaning
sendings array One per recipient, in the order you gave them.
sendings[].id string or null The record of this sending. Null for a failure that couldn’t be recorded.
sendings[].recipient string The address.
sendings[].status string success, failed, or queued: Doxtly e-mail holds the message until it has room to send it, and its row under Sent emails says how it fared.
sendings[].errorMessage string or null Why it failed.

If no message could be sent, the request fails with the status of what stopped it. The failed sendings are still recorded.

Status When
400 The template isn’t active.
400 The organization has no usable email integration: none is active, or several are and none is the default.
400 The email integration isn’t verified.
400 The attachments add up to more than 25 MB.
400 The mailbox provider doesn’t let the connected account send this message.
403 Sending this many would pass your plan’s email limit for the billing period and overage doesn’t cover it, or your plan doesn’t include sending. Nothing is sent.
404 No template has this id in your organization.
409 The integration is Doxtly e-mail and it doesn’t send the message: it is switched off or blocked, the plan’s messages through it are used up, or the message breaks one of its limits, such as on recipients, attachments or links. detail says which.
413 The mail provider refused the message as too large. Outlook takes at most 4 MB.
422 A field fails the rules above, or the subject or body doesn’t compile or render with the data given.
422 The mail provider refused the message, usually over an address.
429 The mailbox has reached its sending limit for now. Try later.
500 The mail server couldn’t be reached, or the message failed for another reason.
503 The mail server failed in a way that may pass. Try later.

The errors every endpoint can answer apply here too.

Terminal window
curl -X POST 'https://api.doxtly.com/v1/email_templates/01a1abe5-221e-74a8-9cb2-d723a4e192dd/send' \
-H "X-Api-Key: $DOXTLY_API_KEY" \
-H "X-Api-Secret: $DOXTLY_API_SECRET" \
-H 'Content-Type: application/json' \
-d '{
"recipients": ["maria.nowak@acme.example", "tom.reed@acme.example"],
"cc": ["training@northbridge.example"],
"replyTo": "training@northbridge.example",
"data": {
"trainee": { "firstName": "Maria" },
"course": { "title": "Negotiation Essentials" }
},
"attachments": [
{
"filename": "certificate.pdf",
"mimetype": "application/pdf",
"content": "JVBERi0xLjcK"
}
]
}'

Response 200:

{
"sendings": [
{
"id": "01a1abe5-26ab-7765-a440-bedf8feb5151",
"recipient": "maria.nowak@acme.example",
"status": "success",
"errorMessage": null
},
{
"id": "01a1abe5-26f7-77f5-b5f5-9c243ac24868",
"recipient": "tom.reed@acme.example",
"status": "success",
"errorMessage": null
}
]
}