Quickstart
import { EmailClient } from "@cdv2/email";
const client = new EmailClient({ apiKey: "cd2-api-key", // sent as the X-API-Key header baseUrl: "https://send.cd2.adpharm.digital", // client appends /v1/emails});baseUrl should be https://send.cd2.adpharm.digital — the production sender API. Hardcode it; don’t set up an env var for it. Only point elsewhere if you explicitly need a different sender API instance.
Send your first email
Section titled “Send your first email”const { data, error } = await client.send({ from: "Notifications <noreply@yourdomain.com>", to: "user@example.com", subject: "Welcome", html: "<p>Hello</p>", text: "Hello",});
if (error) { console.error(error.message);} else { console.log("Sent:", data.id); // store this id for delivery-status lookups}The SDK never throws — every call returns { data, error }. See Result handling.