Authentication and API keys
Every request to the API carries an API key as a bearer token:
curl https://api.postilio.eu/v1/domains \
-H "Authorization: Bearer $POSTILIO_KEY"
SMTP uses the same keys: user name apikey, the key as the password (see Sending email).
Keys
A key belongs to one project and works only on that project's domains, messages, suppressions and webhooks. Create keys in the portal under Keys & SMTP: Owners and Admins of the organization in every project, Developers in the projects they have access to.
- A key is
pk_live_orpk_test_followed by 32 letters and digits. - It is shown once. Postilio stores only a hash of it; the portal shows the first characters, so you can tell keys apart. Lost a key? Revoke it and create a new one.
- Revoking takes effect at once. An SMTP connection that logged in with the key before gets its next message refused.
- Changing a key's name, scopes and restrictions is done in the portal too (Owners, Admins and Developers with access to the project). It holds from the next API call; an SMTP connection that logged in before is checked again at its next message. The key itself and its mode (live or test) never change: for another, create a new key.
- The portal shows when a key was last used (to the minute).
- In the portal, lasting access asks for a recent two-factor code (at most 10 minutes old): creating a key or giving it more, adding a webhook endpoint, changing its URL, rotating its secret or deleting it, adding or removing a domain, removing a suppression and exporting messages or suppressions. The code is asked once and then covers the next 10 minutes. Calls with an API key never ask for it: scripts and servers keep working as they are.
Live and test keys
| What | Live key pk_live_… | Test key pk_test_… |
|---|---|---|
| Checks (sender domain, restrictions, suppression list, validation) | yes | the same |
| Delivers mail | yes | never: every message gets simulated events at once |
| Sandbox and probation limits | yes, while the organization is in the sandbox or the probation after it | no |
| Volume limit | your project and plan limits, and the platform limits | a limit of its own instead: 3,000 recipients a minute and 100,000 a day per project, see Platform limits |
| Counts as usage | yes | no |
| Scopes | any | emails:send, emails:read and domains:read at most |
Test and live messages are kept apart: a test key finds only test messages and a live key only live ones; the other kind answers 404. Webhook endpoints have a mode too: a test endpoint gets the events of test messages only. The simulator addresses are in Suppressions and test mode.
Scopes
A key has one or more scopes. A call outside them answers 403 with {"error": "insufficient_scope"}.
| Scope | Allows |
|---|---|
emails:send | POST /v1/emails, and SMTP submission |
emails:read | GET /v1/emails/{id}, GET /v1/emails/problems |
domains:read | GET /v1/domains, GET /v1/domains/{id}; also on a test key |
domains:manage | everything domains:read allows, plus POST /v1/domains, DELETE /v1/domains/{id}, POST /v1/domains/{id}/check |
suppressions:read | GET /v1/suppressions, also to check one address |
suppressions:manage | everything suppressions:read allows, plus POST /v1/suppressions, DELETE /v1/suppressions/{id} |
webhooks:read | GET /v1/webhooks, GET /v1/webhooks/{id}, GET /v1/webhooks/{id}/deliveries; never the signing secret |
webhooks:manage | everything under /v1/webhooks |
inbound:read | GET under /v1/inbound: receiving domains, routes, received messages with their content, attachments and raw mail (see Inbound mail); also on a test key |
inbound:manage | everything under /v1/inbound |
usage:read | GET /v1/usage, the project's usage per month (see Usage); live keys only, never on by default |
Give each key only what it needs: the key on a web server that sends sign-in codes needs emails:send, nothing more. A plugin that only shows its sender domain's status needs domains:read, not domains:manage; a dashboard that watches your suppressions and webhook deliveries needs suppressions:read and webhooks:read.
Restrictions
Two optional limits per key, set when you create it or later in the portal (at most 20 entries each):
- Sending domains. The key sends only from these domains of the project. A message from another domain answers
422with{"error": "sender_domain_not_allowed_for_key"}; over SMTP theMAIL FROMis refused with553 5.7.1 sender_domain_not_allowed_for_key. - Networks. The key works only from these networks: CIDR (
192.0.2.0/24,2001:db8::/32) or a single address. The address must be the network's own (10.0.0.0/8, not10.0.0.1/8). From anywhere else the answer is403with{"error": "client_ip_not_allowed"}, and over SMTP the login fails with535 5.7.1 client_ip_not_allowed.
Without restrictions a key sends from every verified domain of the project, from anywhere.
Moving a key to another project
An Owner or Admin can move a key to another project of the same organization, on the key's page in the portal. It is the same key: its value, prefix, scopes, networks and mode stay, so your integration keeps working without a change.
- From the next call on, the key sends from the new project's domains and counts against its limits (plan, project and emergency limits). An SMTP connection that is already open switches at its next
MAIL FROM. - What the key sent before stays with the old project, also in
apiKeyofGET /v1/usage, which counts from the move on. - A key limited to sending domains moves only when the new project has those domains verified. Otherwise the portal refuses with
api_key_domains_not_in_targetand names the domains; the limit is never dropped for you. - Moving to another organization is not possible; that is a project transfer.
Errors
| Status | error | Why |
|---|---|---|
401 | invalid_api_key | no Authorization: Bearer pk_… header, or a key that does not exist or was revoked |
403 | insufficient_scope | the key lacks the scope this call needs |
403 | client_ip_not_allowed | the key is restricted to networks this request does not come from |
403 | organization_suspended | Postilio suspended the key's organization; nothing is sent until it is resumed |
403 | project_suspended | the key's project is paused or suspended, see Paused projects |
A key of an organization that is being deleted stops working too, until the deletion is cancelled.
Response headers
Every answer from /v1 carries Cache-Control: no-store, so message data, recipients and webhook secrets are not kept in a browser or proxy cache. Over HTTPS the API sends Strict-Transport-Security as well: a browser that saw it uses only HTTPS for the API host from then on. The other browser security headers (Content-Security-Policy, X-Content-Type-Options: nosniff, Referrer-Policy: no-referrer and the like) are there too; a client on a server can ignore them.
Signing in to the portal
The portal itself is signed in to with an e-mail address, a password and a second factor; the API never uses them. Failed sign-ins are limited so that nobody can guess a password, or shut you out of your own account by failing on purpose:
- Per network. All sign-in steps together, at most 20 attempts a minute from one network: an IPv4 address, or a whole IPv6 /64 (one subscriber's prefix, however many addresses it uses).
- Per account and network. After 10 failed passwords for an address from one network in 15 minutes, that network gets
429 too_many_attemptsfor the address. Other networks are not affected. - Per account. Failures for an address from everywhere count too. After 5 within an hour, a browser that never signed in to the account waits a little longer for each answer (1, 2, 4 … up to 10 seconds); after 50 it gets
429 too_many_attemptsuntil the hour is over. - A browser you signed in with before keeps working. After a correct password, the browser keeps a cookie for 90 days that exempts it from the per-account brake. Resetting your password via Forgot your password? gives the browser you reset it in that cookie too, so a lockout on a new device has a way out through your mailbox.
- You are told. At 25 failures within an hour, the account's owner gets an e-mail (once an hour) and each of their organizations an entry Failed sign-ins in its audit log, with the number of failures and networks, never the addresses.
Only failures count; a successful sign-in takes its attempt back. The answers are the same whether or not an address has an account: the same 401 invalid_credentials for a wrong password and an unknown address, the same 429 and the same waiting time.
Passwords
A portal password has 12 to 256 characters; there are no rules about digits or symbols. A few unrelated words work well. Every new password (when you join, set up your account again, reset or change it) is also checked against Have I Been Pwned's Pwned Passwords, a list of passwords from known data breaches (CC BY 4.0). A password on that list is refused with This password appears in known data breaches. Choose another one.
The check uses k-anonymity: Postilio hashes the password with SHA-1 and sends only the first 5 of its 40 hex characters to api.pwnedpasswords.com (run behind Cloudflare, in the United States). The answer lists every known hash with that beginning, padded with fake entries so its size says nothing, and Postilio compares the rest of the hash itself. Your password, its full hash, your address and your account never leave Postilio, no cookies are sent, and none of it is logged. If the service does not answer within 2 seconds, the password is taken unchecked: the check never keeps you from setting a password.