Brevo
Send emails using the Brevo (formerly Sendinblue) API with @visulima/email
Brevo Provider
The Brevo provider allows you to send emails through the Brevo API, formerly known as Sendinblue.
Runtime Support: Universal (Node.js, Deno, Bun, Cloudflare Workers)
Setup
import { createMail } from "@visulima/email";
import { brevoProvider } from "@visulima/email/providers/brevo";
const mail = createMail(
brevoProvider({
apiKey: process.env.BREVO_API_KEY!,
}),
);Configuration
The BrevoConfig interface extends BaseConfig with the following options:
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
apiKey | string | Yes | - | Your Brevo API key |
endpoint | string | No | https://api.brevo.com/v3 | Custom API endpoint |
hardValidation | boolean | No | false | If true, replyTo arrays are rejected. If false, the first address is used. |
debug | boolean | No | false | Enable debug logging |
logger | Console | No | - | Custom logger instance |
retries | number | No | 3 | Number of retry attempts on failure |
timeout | number | No | 30000 | Request timeout in milliseconds |
Basic Usage
import { MailMessage } from "@visulima/email";
const message = new MailMessage()
.to("user@example.com")
.from("sender@example.com")
.subject("Hello from Brevo")
.html("<h1>Hello World</h1>");
const result = await mail.send(message);Provider-Specific Email Options
The Brevo provider supports additional options through BrevoEmailOptions:
Scheduled Sending
The scheduledAt option accepts an ISO 8601 string or a Unix timestamp in seconds (not milliseconds).
import type { BrevoEmailOptions } from "@visulima/email/providers/brevo";
const options: BrevoEmailOptions = {
from: { email: "sender@example.com" },
to: { email: "user@example.com" },
subject: "Scheduled email",
html: "<h1>Hello</h1>",
scheduledAt: "2025-01-15T10:00:00Z",
};Template-Based Emails
const options: BrevoEmailOptions = {
from: { email: "sender@example.com" },
to: { email: "user@example.com" },
subject: "Template email",
html: "",
templateId: 123,
templateParams: {
name: "John",
company: "Acme",
},
};Batch Sending
const options: BrevoEmailOptions = {
from: { email: "sender@example.com" },
to: { email: "user@example.com" },
subject: "Batch email",
html: "<h1>Hello</h1>",
batchId: "batch-123",
};| Option | Type | Description |
|---|---|---|
tags | string[] | Tags for categorization |
templateId | number | Brevo template ID |
templateParams | Record<string, unknown> | Template parameters |
scheduledAt | string | number | ISO 8601 date string or Unix timestamp (seconds) |
batchId | string | Batch ID for batch sending |
replyTo | EmailAddress | EmailAddress[] | Reply-to address (only one allowed by Brevo) |
Supported Features
| Feature | Supported |
|---|---|
| Attachments | Yes |
| Batch Sending | Yes |
| Custom Headers | Yes |
| HTML | Yes |
| Reply-To | Yes |
| Scheduling | Yes |
| Tagging | Yes |
| Templates | Yes |
| Tracking | Yes |
Additional Methods
Retrieve Email
const provider = brevoProvider({ apiKey: "xxx" });
const result = await provider.getEmail("email-id");Important Notes
- Brevo only supports a single reply-to address. If an array is provided and
hardValidationisfalse(default), the first address is used. IfhardValidationistrue, an error is returned.