Quickstart: send your first email
Sign up, create a key, verify a domain and send. Most of the five minutes is waiting for DNS to update; the API calls themselves take seconds.
Related:Email validationEmail sendingSMTP relay
Checked against the API source on
You need a domain you control and access to its DNS settings. You cannot send from a free mailbox address such as gmail.com: mail has to come from a domain you have verified. If you only want to test validation, you can stop after step 2.
Sign up and create an API key
Create an account, then open API keys and create a key. The full key is shown once, so copy it straight into your secrets manager. For a first try, leave the scopes empty (full access); narrow them later, see Authentication. New accounts include free credits; see pricing for the current allowance.
Shell export SCRUBIMAIL_API_KEY="paste-your-key-here"Every example below reads the key from that variable and sends it in the
X-API-Keyheader. Keep it on your server, never in browser or mobile code.Check an address before you send to it
This is the step most email APIs do not have.
POST /validate/checks syntax, DNS and the mailbox itself. Run it on addresses you do not already trust (signup forms, imported lists) so you do not send to dead mailboxes. A deep check takes a few seconds; add?mode=fastfor a quick syntax and DNS check.curl -X POST "https://api.scrubimail.com/scrubimail/api/v1/validate/" \ -H "X-API-Key: $SCRUBIMAIL_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "email": "[email protected]" }'const res = await fetch("https://api.scrubimail.com/scrubimail/api/v1/validate/", { method: "POST", headers: { "X-API-Key": process.env.SCRUBIMAIL_API_KEY, "Content-Type": "application/json", }, body: JSON.stringify({ "email": "[email protected]" }), }); const data = await res.json(); if (!res.ok) throw new Error(data.error?.message ?? data.error ?? res.statusText);import os import requests payload = { "email": "[email protected]", } res = requests.post( "https://api.scrubimail.com/scrubimail/api/v1/validate/", headers={"X-API-Key": os.environ["SCRUBIMAIL_API_KEY"]}, json=payload, timeout=30, ) data = res.json() res.raise_for_status()<?php $payload = <<<'JSON' { "email": "[email protected]" } JSON; $ch = curl_init('https://api.scrubimail.com/scrubimail/api/v1/validate/'); curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, CURLOPT_HTTPHEADER => [ 'X-API-Key: ' . getenv('SCRUBIMAIL_API_KEY'), 'Content-Type: application/json', ], CURLOPT_POSTFIELDS => $payload, ]); $data = json_decode(curl_exec($ch), true); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch);Send to the address when
is_validistrue. Readverdictandsub_statusfor everything else; see Validation API. Each call costs 1 validation credit.Add your sending domain
Use the domain that appears after the
@in your From address. A subdomain such asmail.yourcompany.comis a good choice because it keeps its reputation separate from your main domain. Keep theidfrom the response: you pass it assending_domain_idwhen you send.curl -X POST "https://api.scrubimail.com/scrubimail/api/v1/send/domains/" \ -H "X-API-Key: $SCRUBIMAIL_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "domain": "yourcompany.com" }'const res = await fetch("https://api.scrubimail.com/scrubimail/api/v1/send/domains/", { method: "POST", headers: { "X-API-Key": process.env.SCRUBIMAIL_API_KEY, "Content-Type": "application/json", }, body: JSON.stringify({ "domain": "yourcompany.com" }), }); const data = await res.json(); if (!res.ok) throw new Error(data.error?.message ?? data.error ?? res.statusText);import os import requests payload = { "domain": "yourcompany.com", } res = requests.post( "https://api.scrubimail.com/scrubimail/api/v1/send/domains/", headers={"X-API-Key": os.environ["SCRUBIMAIL_API_KEY"]}, json=payload, timeout=30, ) data = res.json() res.raise_for_status()<?php $payload = <<<'JSON' { "domain": "yourcompany.com" } JSON; $ch = curl_init('https://api.scrubimail.com/scrubimail/api/v1/send/domains/'); curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, CURLOPT_HTTPHEADER => [ 'X-API-Key: ' . getenv('SCRUBIMAIL_API_KEY'), 'Content-Type: application/json', ], CURLOPT_POSTFIELDS => $payload, ]); $data = json_decode(curl_exec($ch), true); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch);Publish the DNS records
Add these three TXT records at your DNS provider. Replace
yourcompany.comwith your domain and<dkim_public_key>with thedkim_public_keyfrom the previous response.Purpose Type Host Value SPF TXT @v=spf1 include:_spf.scrubimail.com ~allDKIM TXT scrubimail._domainkeyv=DKIM1; k=rsa; p=<dkim_public_key>DMARC TXT _dmarcv=DMARC1; p=none; rua=mailto:[email protected]If you already have an SPF record, add
include:_spf.scrubimail.comto it instead of creating a second one. A domain with two SPF records fails SPF. Many DNS providers add your domain to the host name for you, so enter only@,scrubimail._domainkeyand_dmarcthere. The details and the common mistakes are in Sending setup.Verify the domain
Once the records are live (usually minutes, occasionally up to 48 hours), ask ScrubiMail to check them. The domain is verified when SPF and DKIM pass. If a check fails,
verification_detailssays which record and why; fix it and call the endpoint again.curl -X POST "https://api.scrubimail.com/scrubimail/api/v1/send/domains/a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d/verify/" \ -H "X-API-Key: $SCRUBIMAIL_API_KEY"const res = await fetch("https://api.scrubimail.com/scrubimail/api/v1/send/domains/a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d/verify/", { method: "POST", headers: { "X-API-Key": process.env.SCRUBIMAIL_API_KEY, }, }); const data = await res.json(); if (!res.ok) throw new Error(data.error?.message ?? data.error ?? res.statusText);import os import requests res = requests.post( "https://api.scrubimail.com/scrubimail/api/v1/send/domains/a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d/verify/", headers={"X-API-Key": os.environ["SCRUBIMAIL_API_KEY"]}, timeout=30, ) data = res.json() res.raise_for_status()<?php $ch = curl_init('https://api.scrubimail.com/scrubimail/api/v1/send/domains/a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d/verify/'); curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, CURLOPT_HTTPHEADER => [ 'X-API-Key: ' . getenv('SCRUBIMAIL_API_KEY'), ], ]); $data = json_decode(curl_exec($ch), true); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch);DMARC is checked too, but only bulk sends and campaigns require it. Publish it anyway: Gmail and Yahoo expect it.
Send your first email
from_emailmust be an address on the verified domain, andsending_domain_idis theidfrom step 3. For a first test, send to your own inbox. The call costs 1 sending credit and answers202as soon as the message is accepted.curl -X POST "https://api.scrubimail.com/scrubimail/api/v1/send/" \ -H "X-API-Key: $SCRUBIMAIL_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "sending_domain_id": "a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d", "from_email": "[email protected]", "from_name": "Your Company", "to_email": "[email protected]", "to_name": "Ada Lovelace", "subject": "Welcome, {{first_name|there}}!", "html_content": "<p>Hi {{first_name|there}}, thanks for joining {{company}}.</p>", "text_content": "Hi {{first_name|there}}, thanks for joining {{company}}.", "reply_to": "[email protected]", "tags": [ "welcome" ], "variables": { "company": "Kofi Logistics" } }'const res = await fetch("https://api.scrubimail.com/scrubimail/api/v1/send/", { method: "POST", headers: { "X-API-Key": process.env.SCRUBIMAIL_API_KEY, "Content-Type": "application/json", }, body: JSON.stringify({ "sending_domain_id": "a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d", "from_email": "[email protected]", "from_name": "Your Company", "to_email": "[email protected]", "to_name": "Ada Lovelace", "subject": "Welcome, {{first_name|there}}!", "html_content": "<p>Hi {{first_name|there}}, thanks for joining {{company}}.</p>", "text_content": "Hi {{first_name|there}}, thanks for joining {{company}}.", "reply_to": "[email protected]", "tags": [ "welcome" ], "variables": { "company": "Kofi Logistics" } }), }); const data = await res.json(); if (!res.ok) throw new Error(data.error?.message ?? data.error ?? res.statusText);import os import requests payload = { "sending_domain_id": "a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d", "from_email": "[email protected]", "from_name": "Your Company", "to_email": "[email protected]", "to_name": "Ada Lovelace", "subject": "Welcome, {{first_name|there}}!", "html_content": "<p>Hi {{first_name|there}}, thanks for joining {{company}}.</p>", "text_content": "Hi {{first_name|there}}, thanks for joining {{company}}.", "reply_to": "[email protected]", "tags": [ "welcome", ], "variables": { "company": "Kofi Logistics", }, } res = requests.post( "https://api.scrubimail.com/scrubimail/api/v1/send/", headers={"X-API-Key": os.environ["SCRUBIMAIL_API_KEY"]}, json=payload, timeout=30, ) data = res.json() res.raise_for_status()<?php $payload = <<<'JSON' { "sending_domain_id": "a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d", "from_email": "[email protected]", "from_name": "Your Company", "to_email": "[email protected]", "to_name": "Ada Lovelace", "subject": "Welcome, {{first_name|there}}!", "html_content": "<p>Hi {{first_name|there}}, thanks for joining {{company}}.</p>", "text_content": "Hi {{first_name|there}}, thanks for joining {{company}}.", "reply_to": "[email protected]", "tags": [ "welcome" ], "variables": { "company": "Kofi Logistics" } } JSON; $ch = curl_init('https://api.scrubimail.com/scrubimail/api/v1/send/'); curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, CURLOPT_HTTPHEADER => [ 'X-API-Key: ' . getenv('SCRUBIMAIL_API_KEY'), 'Content-Type: application/json', ], CURLOPT_POSTFIELDS => $payload, ]); $data = json_decode(curl_exec($ch), true); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch);Keep the
message_idfrom the response. If you leave outtext_content, a plain-text version is generated from the HTML.Check the status
Delivery is asynchronous. The message starts as
sendingand moves todeliveredorbounced, usually within about a minute.curl -X GET "https://api.scrubimail.com/scrubimail/api/v1/send/status/d4e5f6a7-2b3c-4d5e-9f01-a2b3c4d5e6f7/" \ -H "X-API-Key: $SCRUBIMAIL_API_KEY"const res = await fetch("https://api.scrubimail.com/scrubimail/api/v1/send/status/d4e5f6a7-2b3c-4d5e-9f01-a2b3c4d5e6f7/", { method: "GET", headers: { "X-API-Key": process.env.SCRUBIMAIL_API_KEY, }, }); const data = await res.json(); if (!res.ok) throw new Error(data.error?.message ?? data.error ?? res.statusText);import os import requests res = requests.get( "https://api.scrubimail.com/scrubimail/api/v1/send/status/d4e5f6a7-2b3c-4d5e-9f01-a2b3c4d5e6f7/", headers={"X-API-Key": os.environ["SCRUBIMAIL_API_KEY"]}, timeout=30, ) data = res.json() res.raise_for_status()<?php $ch = curl_init('https://api.scrubimail.com/scrubimail/api/v1/send/status/d4e5f6a7-2b3c-4d5e-9f01-a2b3c4d5e6f7/'); curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, CURLOPT_HTTPHEADER => [ 'X-API-Key: ' . getenv('SCRUBIMAIL_API_KEY'), ], ]); $data = json_decode(curl_exec($ch), true); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch);Open the message in your inbox and view its source: you want to see
spf=pass,dkim=passanddmarc=pass. If it landed in spam, read the Deliverability guide.
Where to go next
- Framework guidesNext.js, Express, Django, Laravel, Rails, WordPress and Nodemailer.
- DeliverabilitySPF, DKIM, DMARC, warm-up, bounces and unsubscribes.
- Sending APIBulk sends, templates, campaigns, attachments and suppressions.
- Limits and quotasRate limits, daily sending limits and what costs a credit.
- Errors and rate limitsStatus codes, the error body and how to retry.
- MigratingMoving from Resend, SendGrid or Mailgun.
Something missing or wrong? Email [email protected].