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.0The SDK is a pinned optional peer. It is needed only when you import this subpath.
Setup
MailerSend.layerConfig() reads these variables:
| Variable | Required | Value |
|---|---|---|
MAILERSEND_API_KEY | yes | API 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:
| Text | HTML | Both | Sender name | Cc | Bcc | Reply-to | Headers | Attachments | Inline images | Idempotency |
|---|---|---|---|---|---|---|---|---|---|---|
| yes | yes | yes | yes | yes | yes | one | yes | no | no | no |
These fail with UnsupportedFeatureError and acceptance: "notSubmitted" before any request:
- More than one
replyToaddress (featuremultipleReplyTo). - Any attachment (feature
attachments). - An
idempotencyKey(featureidempotency).
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(pathheaders) andacceptance: "notSubmitted". - A send is accepted only on an HTTP 202 response. If MailerSend reports suppressed recipients, the receipt is
partiallyAcceptedwith one outcome per recipient. When every recipient is suppressed the send fails withMessageRejectedError.
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.
field | Raised when |
|---|---|
timeout | The timeout is not finite and positive. |
token | The API key is not printable ASCII without spaces. |
| MailerSend failure | Reason |
|---|---|
HTTP 202 with an ALL_SUPPRESSED warning | MessageRejectedError (acceptance: "rejected") |
| A success status other than 202 | UnexpectedResponseError |
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".