# `Swoosh.Adapters.MailChannels`
[🔗](https://github.com/swoosh/swoosh/blob/v1.30.0/lib/swoosh/adapters/mailchannels.ex#L1)

Sends email using the authenticated MailChannels Email API.

## Configuration

This adapter requires the Req API client. Configure a verified sender domain in
MailChannels and load the API key from a server-side runtime secret:

    # config/runtime.exs
    config :swoosh, :api_client, Swoosh.ApiClient.Req

    config :sample, Sample.Mailer,
      adapter: Swoosh.Adapters.MailChannels,
      api_key: System.fetch_env!("MAILCHANNELS_API_KEY")

    # lib/sample/mailer.ex
    defmodule Sample.Mailer do
      use Swoosh.Mailer, otp_app: :sample
    end

See the [Email API documentation](https://docs.mailchannels.com/api-reference/send/send-an-email).
This uses the authenticated Email API, not the retired Cloudflare Workers endpoint.

## Supported fields

Supports From, To, Cc, Bcc, a non-empty subject, text/HTML content, one Reply-To,
custom headers, and file/binary/inline attachments. At least one To recipient is
required by the API, and To, Cc and Bcc together may not exceed 1,000 recipients.
Bcc recipients remain in their original role. Unsupported provider options, multiple
Reply-To addresses, structural headers and attachment metadata are rejected.

Inline attachments use their `cid` (Swoosh defaults it to the filename) as the
API `content_id`, which must be 1-255 printable ASCII characters without `<`, `>`
or spaces; pass an explicit `cid:` for filenames that don't qualify.

## Responses and transport

HTTP 202 returns `{:ok, %{id: message_id, request_id: request_id}}` with the values
from the response body, or `{:ok, %{}}` if it carries none. Acceptance is not
delivery: final outcomes are reported through MailChannels webhooks, which carry the
same IDs. A 202 whose result is `"failed"` means MailChannels dropped the message and
returns `{:error, {:send_failed, ids}}` with the same `ids` map; the failure reason is
not included. Other statuses return `{:error, {:http_status, status}}`.
Transport errors return `{:error, :transport_failure}` with unknown acceptance.
Response bodies, request contents and keys are not included in adapter errors.

Uses the fixed HTTPS send endpoint, TLS peer verification, bounded timeouts and no
HTTP retries or redirects. Application/job retries are separate: do not blindly
retry an uncertain send. Only `Swoosh.ApiClient.Req` is supported. Per-email transport
options and endpoint overrides are refused; application-level Req settings remain
trusted. Use current patched Req/Finch/Mint dependencies in deployed applications.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
