Skip to main content
ScrubiMail

SDKs and code examples

ScrubiMail is plain JSON over HTTPS, so any HTTP client works. There is no package to install yet; these small, dependency-light examples are what we recommend instead.

Related:Email validationEmail sending

Checked against the API source on

A minimal client

Wrap the two calls most apps need, validate and send, in a few lines. Every client reads the key from SCRUBIMAIL_API_KEY, raises on an error and passes through the parsed JSON. Run them on your server only.

// scrubimail.js: Node 18+ (global fetch), no dependencies
const BASE = "https://api.scrubimail.com/scrubimail/api/v1";

async function request(method, path, body) {
  const res = await fetch(BASE + path, {
    method,
    headers: { "X-API-Key": process.env.SCRUBIMAIL_API_KEY, "Content-Type": "application/json" },
    body: body === undefined ? undefined : JSON.stringify(body),
  });
  const data = res.status === 204 ? null : await res.json();
  if (!res.ok) {
    // Validation errors use { error: { code, message } }; some sending errors use { error: "message" }.
    const err = typeof data?.error === "string" ? { message: data.error } : data?.error ?? {};
    throw Object.assign(new Error(err.message ?? res.statusText), { status: res.status, code: err.code, meta: err.meta });
  }
  return data;
}

export const validate = (email, { fast = false } = {}) =>
  request("POST", `/validate/${fast ? "?mode=fast" : ""}`, { email });

export const send = (message) => request("POST", "/send/", message);
export const messageStatus = (messageId) => request("GET", `/send/status/${messageId}/`);

Recipes

Check an address at signup

Call your own endpoint from the browser, and have your server call ScrubiMail. Use fast mode for the instant check and deep mode before you store the address.

Server route (Node)
import { validate } from "./scrubimail.js";

// POST /api/check-email  { "email": "..." }
export async function checkEmail(req, res) {
  const result = await validate(req.body.email, { fast: true });

  if (result.verification_status === "invalid" || result.verification_status === "do_not_mail") {
    return res.json({ ok: false, reason: result.sub_status, suggestion: result.suggestions[0] ?? null });
  }
  res.json({ ok: true });
}

// On form submit, before saving the account:
export async function confirmEmail(email) {
  const result = await validate(email); // deep
  return result.is_valid; // true only when the mailbox was confirmed
}

Send a receipt

Transactional send
from scrubimail import send, message_status

message = send({
    "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": "Receipt {{order_id}}",
    "html_content": "<p>Hi {{first_name|there}}, thanks for your order {{order_id}}.</p>",
    "variables": {"order_id": "1042"},
    "tags": ["receipt"],
})

print(message["message_id"], message["status"])  # status is "sending"
print(message_status(message["message_id"])["status"])

curl cheat sheet

Common calls
BASE="https://api.scrubimail.com/scrubimail/api/v1"
AUTH="X-API-Key: $SCRUBIMAIL_API_KEY"

# Deep check, then a fast check
curl -X POST "$BASE/validate/" -H "$AUTH" -H "Content-Type: application/json" -d '{"email":"[email protected]"}'
curl -X POST "$BASE/validate/?mode=fast" -H "$AUTH" -H "Content-Type: application/json" -d '{"email":"[email protected]"}'

# Queue a list, then poll
curl -X POST "$BASE/validate-bulk/" -H "$AUTH" -H "Content-Type: application/json" -d '{"emails":["[email protected]","[email protected]"]}'
curl "$BASE/bulk-status/JOB_ID/" -H "$AUTH"

# Domains, then verify
curl "$BASE/send/domains/" -H "$AUTH"
curl -X POST "$BASE/send/domains/DOMAIN_ID/verify/" -H "$AUTH"

# Delivery status and history
curl "$BASE/send/status/MESSAGE_ID/" -H "$AUTH"
curl "$BASE/send/history/?status=bounced" -H "$AUTH"

Every endpoint, with parameters, responses and errors, is in the Validation API and Sending API references. Need an SDK in another language? Tell us at [email protected].

Something missing or wrong? Email [email protected].