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}/`);# scrubimail.py: needs "requests" (pip install requests)
import os
import requests
BASE = "https://api.scrubimail.com/scrubimail/api/v1"
class ScrubiMailError(Exception):
def __init__(self, status, code, message, meta=None):
super().__init__(f"{status} {code}: {message}")
self.status, self.code, self.message, self.meta = status, code, message, meta
def request(method, path, json=None):
res = requests.request(
method,
BASE + path,
headers={"X-API-Key": os.environ["SCRUBIMAIL_API_KEY"]},
json=json,
timeout=30,
)
data = res.json() if res.content else None
if not res.ok:
err = (data or {}).get("error") or {}
if isinstance(err, str): # some sending errors are {"error": "message"}
err = {"message": err}
raise ScrubiMailError(res.status_code, err.get("code"), err.get("message"), err.get("meta"))
return data
def validate(email, fast=False):
return request("POST", "/validate/" + ("?mode=fast" if fast else ""), {"email": email})
def send(message):
return request("POST", "/send/", message)
def message_status(message_id):
return request("GET", f"/send/status/{message_id}/")<?php
// scrubimail.php: needs the curl extension, no packages
const SCRUBIMAIL_BASE = 'https://api.scrubimail.com/scrubimail/api/v1';
function scrubimail_request(string $method, string $path, ?array $body = null): ?array
{
$ch = curl_init(SCRUBIMAIL_BASE . $path);
$options = [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . getenv('SCRUBIMAIL_API_KEY'),
'Content-Type: application/json',
],
];
if ($body !== null) {
$options[CURLOPT_POSTFIELDS] = json_encode($body);
}
curl_setopt_array($ch, $options);
$raw = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = $raw === '' || $raw === false ? null : json_decode($raw, true);
if ($status >= 400) {
$err = $data['error'] ?? [];
$message = is_string($err) ? $err : ($err['message'] ?? "HTTP $status");
throw new RuntimeException("$status: $message");
}
return $data;
}
function scrubimail_validate(string $email, bool $fast = false): array
{
return scrubimail_request('POST', '/validate/' . ($fast ? '?mode=fast' : ''), ['email' => $email]);
}
function scrubimail_send(array $message): array
{
return scrubimail_request('POST', '/send/', $message);
}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.
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
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
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].