Mailchimp Transactional
Send email through Mailchimp Transactional with the @effect-kit/emails/mailchimp-transactional Layer.
The @effect-kit/emails/mailchimp-transactional subpath sends messages through Mailchimp Transactional and provides the Email service.
Installation
npm install @effect-kit/emails effect @mailchimp/mailchimp_transactional@1.4.1The SDK is a pinned optional peer. It is needed only when you import this subpath.
Setup
MailchimpTransactional.layerConfig() reads these variables:
| Variable | Required | Value |
|---|---|---|
MAILCHIMP_TRANSACTIONAL_API_KEY | yes | API key |
Example (Sending a Message With Mailchimp Transactional)
import { , , } from "effect";
import { } from "@effect-kit/emails";
import * as from "@effect-kit/emails/mailchimp-transactional";
const = .().(
.(.(.())),
);
const = .(function* () {
const = yield* ;
return yield* .({
: "hello@example.com",
: "ada@example.com",
: "Welcome",
: "Your account is ready.",
});
});
.(.(.()));Use a from address your Mailchimp Transactional account is allowed to send from.
Options
MailchimpTransactional.layer takes these options. layerConfig builds the same object from a Config.
Prop
Type
Capabilities
Mailchimp Transactional 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 | multiple | yes | yes | no | no |
These fail with UnsupportedFeatureError and acceptance: "notSubmitted" before any request:
- An attachment with a
contentId(featureinlineAttachments). - An
idempotencyKey(featureidempotency).
Idempotency
Not supported. A key fails with UnsupportedFeatureError before sending.
Provider notes
- Recipients are sent with
preserve_recipients: true, so everyto,ccandbccrecipient is listed in the message headers each recipient sees. - Mailchimp answers per recipient. The statuses
sent,queuedandscheduledcount as accepted, andrejectedandinvalidas rejected. Any other status fails withUnexpectedResponseError. - When some recipients are rejected the receipt is
partiallyAcceptedwith one outcome per recipient. When all are rejected the send fails withMessageRejectedError. Ahard_bouncereject reason is kept asrejectionCode.
Using your own client
layerClient takes any object with messages.send(body), which the client returned by the SDK has. options is optional.
Example (Borrowing a Mailchimp Transactional Client)
import mailchimp from "@mailchimp/mailchimp_transactional";
import * as MailchimpTransactional from "@effect-kit/emails/mailchimp-transactional";
const client = mailchimp("fake-key");
const EmailLive = MailchimpTransactional.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: "mailchimp-transactional" 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. |
baseUrl | The URL is not http or https, or has credentials, a query or a fragment. |
| Mailchimp response | Reason |
|---|---|
status: "error" with name Invalid_Key | AuthenticationError |
status: "error" with name PaymentRequired | QuotaExceededError |
Every recipient rejected or invalid | MessageRejectedError |
Other status: "error" responses fail with ProviderError and acceptance: "rejected". The error name is kept as providerCode only for the two names above.
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".