Sending Emails
Send high-deliverability transactional emails with HTML, text, attachments, custom headers, and scheduled delivery.
Multivrs Mail provides a unified, edge-optimized API for sending transactional messages, alerts, invoices, and password resets with sub-50ms delivery times.
Basic Email Dispatch
To send an email, initialize the MultivrsMail client and pass the sender, recipient, subject, and content:
import { MultivrsMail } from "@multivrs/mail";
const mail = new MultivrsMail();
const { data, error } = await mail.emails.send({
from: "Acme <hello@yourdomain.com>",
to: "user@example.com",
subject: "Welcome to Acme",
html: "<p>Thanks for signing up! We're thrilled to have you on board.</p>",
text: "Thanks for signing up! We're thrilled to have you on board.",
});
if (error) {
console.error("Failed to dispatch email:", error);
} else {
console.log("Email queued with ID:", data?.id);
}If MULTIVRS_API_KEY is defined in your environment variables, new MultivrsMail() automatically uses it without needing an explicit argument.
File Attachments
Attach PDFs, invoices, spreadsheets, or images. Attachments support raw Buffers, Uint8Array (in edge workers), or Base64-encoded strings:
import { readFileSync } from "node:fs";
import { MultivrsMail } from "@multivrs/mail";
const mail = new MultivrsMail();
const invoiceBuffer = readFileSync("./receipt-4091.pdf");
await mail.emails.send({
from: "billing@yourdomain.com",
to: "client@company.com",
subject: "Invoice #4091 for March 2026",
html: "<p>Your March receipt is attached. Thank you for your business!</p>",
attachments: [
{
filename: "invoice-4091.pdf",
content: invoiceBuffer,
contentType: "application/pdf",
},
],
});Scheduled Delivery
Schedule messages to be sent at an exact future time. Provide a Date object or an ISO 8601 string:
const tomorrow = new Date(Date.now() + 24 * 60 * 60 * 1000);
await mail.emails.send({
from: "renewals@yourdomain.com",
to: "customer@example.com",
subject: "Your Subscription Renews Tomorrow",
html: "<p>Friendly reminder that your Multivrs subscription renews tomorrow.</p>",
scheduledAt: tomorrow,
});Scheduled emails remain in a pending state until their trigger timestamp. You can cancel any scheduled email prior to dispatch with mail.emails.cancel(id).
CC, BCC & Custom Headers
Send to multiple recipients, add audit BCCs, or attach custom tracking headers:
await mail.emails.send({
from: "orders@yourdomain.com",
to: ["customer@example.com"],
cc: ["finance@yourdomain.com"],
bcc: ["audit-log@internal.company.com"],
replyTo: ["support@yourdomain.com"],
headers: {
"X-Order-Id": "ord_8829103",
"X-Entity-Ref-ID": "batch-march-2026",
},
subject: "Order Confirmation #ord_8829103",
html: "<p>Your order has been confirmed.</p>",
});Tagging for Analytics
Attach custom tags to segment your email deliverability, bounce rates, and open rates in the Multivrs Mail dashboard:
await mail.emails.send({
from: "noreply@yourdomain.com",
to: "user@example.com",
subject: "Your One-Time Code",
html: "<p>Your login code is 884-291.</p>",
tags: [
{ name: "category", value: "auth-otp" },
{ name: "environment", value: "production" },
],
});