Skip to content

Documentation

Send email with curl.

Works with: Any language that can make an HTTPS request.

Set your key

Create a key under API keys in the dashboard. It is shown once; keep it in an environment variable on your server.

Nothing to install
export MAILTRUSS_API_KEY=ms_live_…

Send an email

This sends one message and passes an idempotency key, so repeating the request can never deliver it twice. Send an Idempotency-Key header. The same key never sends twice, so you can repeat the request after a timeout or a 5xx.

terminal
curl -X POST https://mailtruss.com/api/v1/emails \
-H "Authorization: Bearer $MAILTRUSS_API_KEY" \
-H "Idempotency-Key: order-1042-receipt" \
-H "Content-Type: application/json" \
-d '{ "from": "hello@yourdomain.com", "to": "user@example.com", "subject": "Hi", "text": "Hello" }'

The response is { "id": "…" }. Fetch the message's delivery timeline, what each event proves, and a diagnosis if something went wrong:

terminal
curl https://mailtruss.com/api/v1/emails/EMAIL_ID/events \
-H "Authorization: Bearer $MAILTRUSS_API_KEY"

More on what you can put in a message (cc, bcc, attachments, tags, templates, scheduling) is under Sending.

Handle errors

Errors are JSON with a name and a message, and every response carries an x-request-id header you can search in the dashboard's API logs. Every error name, with its cause and fix, is in the error catalogue.

Other languages

Last updated

Something wrong or unclear on this page?

Report an issue