Documentation for agents: an index at /llms.txt, every docs page in one file at /llms-full.txt, and Markdown for any docs page by adding .md to its URL.

Effect KitEmails

MailerSend

Send email through MailerSend with the @effect-kit/emails/mailersend Layer.

The @effect-kit/emails/mailersend subpath sends messages through MailerSend and provides the Email service.

Installation

npm install @effect-kit/emails effect mailersend@3.6.0

The SDK is a pinned optional peer. It is needed only when you import this subpath.

Setup

MailerSend.layerConfig() reads these variables:

VariableRequiredValue
MAILERSEND_API_KEYyesAPI key

Example (Sending a Message With MailerSend)

import { , ,  } from "effect";
import {  } from "@effect-kit/emails";
import * as  from "@effect-kit/emails/mailersend";

const  = .().(
  .(.(.())),
);

const  = .(function* () {
  const  = yield* ;
  return yield* .({
    : "hello@example.com",
    : "ada@example.com",
    : "Welcome",
    : "Your account is ready.",
  });
});

.(.(.()));

Use a from address your MailerSend account is allowed to send from.

Options

MailerSend.layer takes these options. layerConfig builds the same object from a Config.

Prop

Type

Capabilities

MailerSend reports this in email.capabilities:

TextHTMLBothSender nameCcBccReply-toHeadersAttachmentsInline imagesIdempotency
yesyesyesyesyesyesoneyesnonono

These fail with UnsupportedFeatureError and acceptance: "notSubmitted" before any request:

  • More than one replyTo address (feature multipleReplyTo).
  • Any attachment (feature attachments).
  • An idempotencyKey (feature idempotency).

Idempotency

Not supported. A key fails with UnsupportedFeatureError before sending.

Provider notes

  • MailerSend takes one reply-to address and no attachments through this package. Both fail before sending.
  • Header names may contain only letters, digits and hyphens. Any other name fails with InvalidMessageError (path headers) and acceptance: "notSubmitted".
  • A send is accepted only on an HTTP 202 response. If MailerSend reports suppressed recipients, the receipt is partiallyAccepted with one outcome per recipient. When every recipient is suppressed the send fails with MessageRejectedError.

Using your own client

layerClient takes any object with email.send(message), which a MailerSend client has. options is optional. The client must return the response object with statusCode, headers and body, which is what the SDK does.

Example (Borrowing a MailerSend Client)

import { MailerSend } from "mailersend";
import * as MailerSendEmail from "@effect-kit/emails/mailersend";

const client = new MailerSend({ apiKey: "fake-key" });

const EmailLive = MailerSendEmail.layerClient(client);

You own a borrowed client. The Layer never closes it, and the client keeps its own retry, timeout and logging policy.

Errors

ProviderConfigurationError carries provider: "mailersend" and a field naming the bad option. Layer construction fails with it, and layerClient fails with it for the client options.

fieldRaised when
timeoutThe timeout is not finite and positive.
tokenThe API key is not printable ASCII without spaces.
MailerSend failureReason
HTTP 202 with an ALL_SUPPRESSED warningMessageRejectedError (acceptance: "rejected")
A success status other than 202UnexpectedResponseError

Any other HTTP status uses the shared mapping: 401 is AuthenticationError, 403 PermissionDeniedError, 429 RateLimitedError, 400 and 422 InvalidMessageError, 5xx ProviderUnavailableError, and anything else ProviderError. acceptance is rejected for a 4xx status other than 409 and unknown otherwise. See Errors. A network failure with no status is TransportError, and ETIMEDOUT or ECONNABORTED is TimeoutError, both with acceptance: "unknown".