EmailProvidersHTTP

HTTP

Send emails using a generic HTTP API with @visulima/email

HTTP Provider

The HTTP provider allows you to send emails through any generic HTTP API endpoint. This is useful for custom email services or internal APIs that accept email payloads.

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

Setup

import { createMail } from "@visulima/email";
import { httpProvider } from "@visulima/email/providers/http";

const mail = createMail(
    httpProvider({
        endpoint: "https://my-email-api.example.com/send",
        apiKey: process.env.API_KEY!,
    }),
);

Configuration

The HttpEmailConfig interface has the following options:

OptionTypeRequiredDefaultDescription
endpointstringYes-The HTTP endpoint URL to send to
apiKeystringNo-API key for authentication
headersRecord<string, string>No-Custom HTTP headers for all requests
method"GET" | "POST" | "PUT"No"POST"HTTP method to use

Note: The HTTP provider does not extend BaseConfig and does not support debug, logger, retries, or timeout options from the base configuration.

Basic Usage

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

const message = new MailMessage()
    .to("user@example.com")
    .from("sender@example.com")
    .subject("Hello via HTTP")
    .html("<h1>Hello World</h1>");

const result = await mail.send(message);

Provider-Specific Email Options

The HTTP provider supports additional options through HttpEmailOptions:

import type { HttpEmailOptions } from "@visulima/email/providers/http";

const options: HttpEmailOptions = {
    from: { email: "sender@example.com" },
    to: { email: "user@example.com" },
    subject: "Hello",
    html: "<h1>Hello</h1>",
    endpointOverride: "https://other-api.example.com/send",
    methodOverride: "PUT",
    customParams: {
        priority: "high",
        trackingId: "abc-123",
    },
};
OptionTypeDescription
customParamsRecord<string, unknown>Custom parameters in the request payload
endpointOverridestringOverride the endpoint for this specific email
methodOverride"GET" | "POST" | "PUT"Override the HTTP method for this email

Supported Features

FeatureSupported
AttachmentsYes
Batch SendingNo
Custom HeadersYes
HTMLYes
Reply-ToYes
SchedulingNo
TaggingNo
TemplatesNo
TrackingNo
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