EmailProvidersMandrill

Mandrill

Send emails using Mailchimp Transactional Email (Mandrill) with @visulima/email

Mandrill Provider

The Mandrill provider allows you to send emails through Mailchimp Transactional Email (Mandrill).

Runtime Support: Universal (Node.js, Deno, Bun, Cloudflare Workers)

Setup

import { createMail } from "@visulima/email";
import { mandrillProvider } from "@visulima/email/providers/mandrill";

const mail = createMail(
    mandrillProvider({
        apiKey: process.env.MANDRILL_API_KEY!,
    }),
);

Configuration

The MandrillConfig interface extends BaseConfig with the following options:

OptionTypeRequiredDefaultDescription
apiKeystringYes-Your Mandrill API key
endpointstringNohttps://mandrillapp.com/api/1.0Custom API endpoint
debugbooleanNofalseEnable debug logging
loggerConsoleNo-Custom logger instance
retriesnumberNo3Number of retry attempts
timeoutnumberNo30000Request 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 Mandrill")
    .html("<h1>Hello World</h1>");

const result = await mail.send(message);

Provider-Specific Email Options

The Mandrill provider supports additional options through MandrillEmailOptions:

import type { MandrillEmailOptions } from "@visulima/email/providers/mandrill";

const options: MandrillEmailOptions = {
    from: { email: "sender@example.com" },
    to: { email: "user@example.com" },
    subject: "Hello",
    html: "<h1>Hello {{name}}</h1>",
    tags: ["welcome", "onboarding"],
    globalMergeVars: [
        { name: "company", content: "Acme Corp" },
    ],
    mergeVars: [
        {
            rcpt: "user@example.com",
            vars: [{ name: "name", content: "John" }],
        },
    ],
    metadata: { campaign: "onboarding-2025" },
    subaccount: "client-123",
};
OptionTypeDescription
tagsstring[]Tags for categorization
templateNamestringMandrill template name
templateContent{ name: string; content: string }[]Template content blocks
templateVariables{ name: string; content: unknown }[]Template variables (merge vars)
globalMergeVars{ name: string; content: unknown }[]Global merge variables
mergeVars{ rcpt: string; vars: { name: string; content: unknown }[] }[]Per-recipient merge variables
metadataRecord<string, string>Metadata key-value pairs
sendAtstringSend at timestamp (ISO 8601)
subaccountstringSubaccount ID
googleAnalyticsCampaignstringGoogle Analytics campaign name
googleAnalyticsDomainsstring[]Google Analytics domains

Supported Features

FeatureSupported
AttachmentsYes
Batch SendingYes
Custom HeadersYes
HTMLYes
Reply-ToYes
SchedulingYes
TaggingYes
TemplatesYes
TrackingYes
Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues