Integration guide
From an API key to your first delivered message, and what to have in place before real traffic. Pair it with the API reference.
Get an API key
Keys are issued per integration — write to hello@sendpetrel.com with your application's name, the domain you will send from and the kinds of mail (transactional, marketing). You receive a tenant and a key such as
edg_yourapp_…, shown once.Store it as a secret in your application's environment (never in the repository or the browser):
SENDPETREL_API_KEY=edg_yourapp_… SENDPETREL_BASE_URL=https://api.sendpetrel.comCheck that it works:
curl -s https://api.sendpetrel.com/v1/usage \ -H "Authorization: Bearer $SENDPETREL_API_KEY"Register your sending domain
Use a domain (or subdomain) you control, for example
mail.yourapp.comoryourapp.com. Mail sent from your own domain builds your own reputation, so this is the right choice for production.No domain of your own yet? We can set up a managed sending subdomain such asyourapp.sendpetrel.com: you register it in this step as usual, and we publish its DNS records for you, so you can skip step 3. Its reputation is shared with the gateway, so treat it as a way to start, not a long-term home. The baresendpetrel.comdomain is not available for integrations.curl -s https://api.sendpetrel.com/v1/sending-domains \ -H "Authorization: Bearer $SENDPETREL_API_KEY" \ -H "Content-Type: application/json" \ -d '{"domain": "yourapp.com"}'Keep the returned
domain_id. The domain starts aspending.Publish the DNS records
curl -s https://api.sendpetrel.com/v1/sending-domains/$DOMAIN_ID/dns-records \ -H "Authorization: Bearer $SENDPETREL_API_KEY"Add every record it lists at your DNS provider. They look like this (values are specific to your domain):
Purpose Type Name Value Ownership TXT _edg-verification.yourapp.comedg-verification=…SPF TXT yourapp.cominclude include:spf.sendpetrel.comin your one SPF recordDKIM TXT postal-xxxxxx._domainkey.yourapp.comv=DKIM1; … p=…Return path CNAME psrp.yourapp.comrp.sendpetrel.comDMARC (recommended) TXT _dmarc.yourapp.comv=DMARC1; p=none; …If you use Cloudflare, set the CNAME to DNS only (grey cloud). Keep a single SPF record per name — merge the include into an existing one rather than adding a second.Verify the domain
curl -s -X POST https://api.sendpetrel.com/v1/sending-domains/$DOMAIN_ID/verification-checks \ -H "Authorization: Bearer $SENDPETREL_API_KEY"Each record comes back
pass,failormissing. DNS can take a few minutes to propagate; checks are rate-limited, so wait between attempts. When all required records pass, the domain is reviewed and switched toverified, after which it can send.Send your first message
Use a stable
Idempotency-Keyper logical email (for examplepassword-reset-{user_id}-{token_id}): if your request times out, retry with the same key and body — the gateway returns the original result instead of sending twice.# Python (requests) import os, requests r = requests.post( os.environ["SENDPETREL_BASE_URL"] + "/v1/messages", headers={"Authorization": "Bearer " + os.environ["SENDPETREL_API_KEY"], "Idempotency-Key": f"welcome-{user.id}"}, json={"from": "YourApp <hello@yourapp.com>", "to": [user.email], "subject": "Welcome to YourApp", "text": text_body, "html": html_body, "tags": {"kind": "welcome"}}, timeout=15) r.raise_for_status() message_id = r.json()["message_id"]// Node.js (fetch) const res = await fetch(`${process.env.SENDPETREL_BASE_URL}/v1/messages`, { method: "POST", headers: { Authorization: `Bearer ${process.env.SENDPETREL_API_KEY}`, "Content-Type": "application/json", "Idempotency-Key": `receipt-${order.id}` }, body: JSON.stringify({ from: "YourApp <orders@yourapp.com>", to: [order.email], subject: `Receipt for order ${order.id}`, text, html }), }); if (res.status !== 202) throw new Error(`sendpetrel ${res.status}`); const { message_id } = await res.json();Track delivery
Store the
message_idwith your own record. ReadGET /v1/messages/{message_id}for the current state, or pollGET /v1/eventswith its cursor to sync outcomes for all messages:delivered,deferred(retried automatically),bounced,failed, complaints and unsubscribes.Handle errors
Response What to do 400/422Fix the request; the problem document names the field. 422 domain_not_verifiedmeans thefromdomain is not verified yet; suppressed recipients are reported per recipient. Do not retry unchanged.401/403Wrong, revoked or expired key, or a key without the scope the route needs. 409Same Idempotency-Keywith a different body, or the first request is still in progress.429Rate limit or daily quota reached; wait for Retry-After.5xx/ timeoutRetry with backoff using the same Idempotency-Key.Respect opt-outs
Bounced and complaining addresses are suppressed for you; check
GET /v1/suppressionsbefore re-adding anyone.Send newsletters and promotions with
"category": "marketing"(and anunsubscribe_topicif you have several lists). For marketing mail the gateway adds theList-UnsubscribeandList-Unsubscribe-Postheaders itself, which make mail apps show a one-click Unsubscribe button; each recipient gets their own link, so a marketing message is addressed to one recipient. Mirror opt-outs into your app withGET /v1/unsubscribes.Marketing mail must also carry a visible unsubscribe link and your postal address (CAN-SPAM). Until the gateway can add them for you, include both in your message footer.Before real traffic
- All required DNS records pass and the domain is
verified; DMARC is published. - Every send uses a deterministic
Idempotency-Keyand a 10–15 s timeout. - Errors are handled as above, and
message_ids are stored. - Marketing mail uses
category: marketing; consent is recorded in your app. - Start small: tens of messages a day to engaged recipients, then roughly double weekly while bounces stay under 2% and complaints under 0.1%.
- All required DNS records pass and the domain is