EmailProvidersRound Robin

Round Robin

Load balance email sending across multiple providers with @visulima/email

Round Robin Provider

The Round Robin provider distributes email sending across multiple providers in a round-robin fashion, providing load balancing for high-volume email sending.

Runtime Support: Depends on the wrapped providers

Setup

import { createMail } from "@visulima/email";
import { roundRobinProvider } from "@visulima/email/providers/roundrobin";
import { resendProvider } from "@visulima/email/providers/resend";
import { sendGridProvider } from "@visulima/email/providers/sendgrid";

const mail = createMail(
    roundRobinProvider({
        mailers: [
            resendProvider({ apiKey: process.env.RESEND_API_KEY! }),
            sendGridProvider({ apiKey: process.env.SENDGRID_API_KEY! }),
        ],
    }),
);

Configuration

The RoundRobinConfig interface extends BaseConfig with the following options:

OptionTypeRequiredDefaultDescription
mailersunknown[]Yes-Array of provider instances or provider factory functions
retryAfternumberNo60Time in milliseconds to wait before retrying with next unavailable provider
debugbooleanNofalseEnable debug logging
loggerConsoleNo-Custom logger instance

How It Works

  1. Each email is sent using the next provider in the rotation.
  2. If a provider is unavailable, the round robin moves to the next available provider.
  3. The rotation continues cyclically through all providers.
  4. If all providers are unavailable, an error is returned.

Basic Usage

import { MailMessage } from "@visulima/email";

// First email goes to provider 1
await mail.send(new MailMessage().to("a@example.com").from("sender@example.com").subject("Email 1").html("<h1>1</h1>"));

// Second email goes to provider 2
await mail.send(new MailMessage().to("b@example.com").from("sender@example.com").subject("Email 2").html("<h1>2</h1>"));

// Third email goes back to provider 1
await mail.send(new MailMessage().to("c@example.com").from("sender@example.com").subject("Email 3").html("<h1>3</h1>"));

Supported Features

The round robin provider supports whatever features the underlying providers support. Feature availability depends on which provider is selected for a given email.

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