EmailProvidersSparkPost

SparkPost

Send emails using the SparkPost Transmissions API with @visulima/email

SparkPost Provider

The SparkPost provider sends emails through the SparkPost Transmissions API.

Runtime Support: Universal (Node.js, Deno, Bun, Cloudflare Workers) — uses the Fetch API.

Setup

import { createMail } from "@visulima/email";
import { sparkpostProvider } from "@visulima/email/providers/sparkpost";

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

Configuration

The SparkPostConfig interface extends BaseConfig with the following options:

OptionTypeRequiredDefaultDescription
apiKeystringYes-Your SparkPost API key (sent as the Authorization header)
endpointstringNohttps://api.sparkpost.com/api/v1Custom API endpoint. Use https://api.eu.sparkpost.com/api/v1 (EU).
debugbooleanNofalseEnable debug logging
loggerConsoleNo-Custom logger instance
retriesnumberNo3Number of retry attempts
timeoutnumberNo30000Request timeout in milliseconds

Basic Usage

const result = await mail.send({
    from: { email: "noreply@example.com", name: "My App" },
    to: { email: "user@example.com" },
    subject: "Hello from SparkPost",
    html: "<h1>Welcome!</h1>",
    text: "Welcome!",
});

Provider-Specific Email Options

The SparkPostEmailOptions interface extends EmailOptions with:

OptionTypeDescription
campaignIdstringCampaign id applied to the transmission
templateIdstringStored template id to send instead of inline content
trackOpensbooleanWhether open tracking is enabled
trackClicksbooleanWhether click tracking is enabled
await mail.send({
    from: { email: "noreply@example.com" },
    to: { email: "user@example.com" },
    subject: "Campaign email",
    html: "<p>Hello</p>",
    campaignId: "summer-2026",
    trackOpens: true,
    trackClicks: true,
});

Supported Features

  • ✅ Attachments
  • ✅ Batch sending
  • ✅ Custom headers
  • ✅ HTML & text bodies
  • ✅ Reply-To
  • ✅ Tagging
  • ✅ Templates
  • ✅ Open/click tracking
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