Skip to content

Sending API

The FrontEngine HTTP API implements the contract of the Postal API (/api/v1). Libraries and integrations written for Postal work by changing the base URL and the key.

Base URL and authentication

https://api.frontengine.net/api/v1/

Every request carries the server credential's key in the X-Server-API-Key header:

POST /api/v1/send/message HTTP/1.1
Content-Type: application/json
X-Server-API-Key: YOUR_KEY

Parameters go in a JSON body with Content-Type: application/json. A form with a params field holding the JSON is also accepted.

Response format

Every response has the same envelope:

{
  "status": "success",
  "time": 0.042,
  "flags": {},
  "data": {}
}
Field Description
status success, error or parameter-error
time processing time, in seconds
flags empty object
data the result, or the error details

HTTP 200 does not mean success

As in Postal, authentication and validation errors answer HTTP 200 with status set to error or parameter-error. Always check the status field. HTTP codes other than 200 are listed under Errors.

Send a message

POST /api/v1/send/message

FrontEngine builds the MIME message from the fields.

Parameters

Parameter Type Required Description
from string yes Sender, name <address> or just the address. The domain must be verified for the server.
to array of strings conditional Recipients. At most 50.
cc array of strings conditional Carbon copy recipients. At most 50.
bcc array of strings conditional Blind carbon copy recipients. At most 50.
subject string no Subject.
plain_body string conditional Text body.
html_body string conditional HTML body.
sender string no Sender header.
reply_to string no Reply-To header.
tag string no One tag for the message. It comes back in webhooks and in the status lookup.
headers object no Additional headers, name and value.
attachments array of objects no Attachments: name, content_type and data (base64 content).

Rules:

  • At least one recipient in to, cc or bcc is required, and at least one of plain_body and html_body.
  • to, cc and bcc accept an array or a single string with comma-separated addresses.
  • With both plain_body and html_body, the message is sent as multipart/alternative.
  • In headers, the headers the API writes itself are ignored: From, Sender, To, Cc, Bcc, Reply-To, Subject, Date, Message-ID, MIME-Version, Content-Type, Content-Transfer-Encoding, Received, DKIM-Signature and Return-Path.
  • A header value or subject containing a line break is refused with parameter-error.
  • An address repeated across to, cc and bcc receives a single copy.
  • Each recipient becomes its own message, with its own id and token.

Example

curl -sS https://api.frontengine.net/api/v1/send/message \
  -H "X-Server-API-Key: $FRONTENGINE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "My Store <[email protected]>",
    "to": ["[email protected]"],
    "reply_to": "[email protected]",
    "subject": "Order 1234 confirmed",
    "plain_body": "Hello! Your order 1234 has been confirmed.",
    "html_body": "<p>Hello! Your order <strong>1234</strong> has been confirmed.</p>",
    "tag": "order-confirmed",
    "headers": { "X-Order": "1234" }
  }'
import base64
import os
import requests

with open("invoice.pdf", "rb") as f:
    pdf = base64.b64encode(f.read()).decode()

r = requests.post(
    "https://api.frontengine.net/api/v1/send/message",
    headers={"X-Server-API-Key": os.environ["FRONTENGINE_KEY"]},
    json={
        "from": "My Store <[email protected]>",
        "to": ["[email protected]"],
        "subject": "Your invoice",
        "plain_body": "The invoice is attached.",
        "tag": "invoice",
        "attachments": [
            {"name": "invoice.pdf", "content_type": "application/pdf", "data": pdf}
        ],
    },
    timeout=30,
)
body = r.json()
if r.status_code != 200 or body["status"] != "success":
    raise RuntimeError(f"send failed: HTTP {r.status_code} {body}")
for rcpt, m in body["data"]["messages"].items():
    print(rcpt, m["id"], m["token"])
const res = await fetch("https://api.frontengine.net/api/v1/send/message", {
  method: "POST",
  headers: {
    "X-Server-API-Key": process.env.FRONTENGINE_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    from: "My Store <[email protected]>",
    to: ["[email protected]"],
    subject: "Order 1234 confirmed",
    plain_body: "Hello! Your order 1234 has been confirmed.",
    tag: "order-confirmed",
  }),
});
const body = await res.json();
if (!res.ok || body.status !== "success") {
  throw new Error(`send failed: HTTP ${res.status} ${JSON.stringify(body)}`);
}
console.log(body.data.messages);

Success response

{
  "status": "success",
  "time": 0.042,
  "flags": {},
  "data": {
    "message_id": "[email protected]",
    "messages": {
      "[email protected]": { "id": 1042, "token": "Zp3kQ9xT" }
    }
  }
}
Field Description
data.message_id Value of the Message-ID header, without the <> signs.
data.messages One entry per recipient. The key is the address.
data.messages[].id The message's number within the server. Use it in the status lookup; it is the same id webhooks carry.
data.messages[].token The message's token.

Success means the message was accepted and queued. The delivery outcome arrives through webhooks.

Send a ready-made MIME message

POST /api/v1/send/raw

Use it when your application already generates the complete message (RFC 5322).

Parameter Type Required Description
mail_from string yes Envelope sender address.
rcpt_to array of strings yes Recipients. Must be an array.
data string yes The complete message, base64 encoded.
RAW=$(printf 'From: [email protected]\r\nTo: [email protected]\r\nSubject: Raw test\r\n\r\nMessage body.\r\n' | base64 | tr -d '\n')

curl -sS https://api.frontengine.net/api/v1/send/raw \
  -H "X-Server-API-Key: $FRONTENGINE_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"mail_from\": \"[email protected]\", \"rcpt_to\": [\"[email protected]\"], \"data\": \"$RAW\"}"

The response has the same format as send/message. data.message_id is the Message-ID of the message sent, or null if it has no such header.

Errors

Validation and authentication errors answer HTTP 200:

{
  "status": "error",
  "time": 0.003,
  "flags": {},
  "data": {
    "code": "NoContent",
    "message": "There is no content defined for this e-mail"
  }
}
data.code Cause
AccessDenied X-Server-API-Key header missing.
InvalidServerAPIKey The key is not valid.
ServerSuspended The server is suspended.
NoRecipients No recipients.
TooManyToAddresses, TooManyCCAddresses, TooManyBCCAddresses More than 50 addresses in the field.
NoContent Both plain_body and html_body are missing.
FromAddressMissing from is missing.
UnauthenticatedFromAddress from is invalid, or the address is not authorized for this server.
AttachmentMissingName, AttachmentMissingData Attachment without name, or with data empty or not base64.
MessageRejected The message was permanently refused for another reason (for example, size). The message field carries the reason.

Missing or malformed parameters answer with status set to parameter-error and only data.message.

HTTP codes other than 200:

HTTP data.code What to do
404 NotFound Unknown path. Check the URL.
405 MethodNotAllowed Use POST.
413 RequestTooLarge Request body too large.
500 InternalServerError A failure on our side. Retry with increasing waits.
503 TemporaryFailure The message could not be accepted right now. Retry.

When to retry

Retry only on responses other than HTTP 200 (500 and 503) and on network failures. An HTTP 200 with status error or parameter-error is final: fix the request. There is no idempotency key; a retry after a network timeout may produce a second message.

The full reference is in Errors.

Not available yet

Message templates, scheduled sending, batch sending with per-recipient personalization, idempotency keys and arbitrary per-message metadata do not exist. The sending API has no published per-request rate limit.

Next steps