MillionSend.Emails (MillionSend v0.4.0)

Copy Markdown View Source

Send, list, fetch, reschedule and cancel emails.

Input maps use snake_case keys and are sent to the API as given — every key reaches the wire: from, to, subject, html, text, cc, bcc, reply_to, scheduled_at, tags, topic_id, attachments, headers and template. :to, :cc, :bcc and :reply_to take a string or a list of strings.

MillionSend.Emails.send(%{
  from: "Acme <onboarding@acme.dev>",
  to: "delivered@resend.dev",
  subject: "Hello",
  html: "<strong>it works</strong>",
  tags: [%{name: "campaign", value: "welcome"}],
  attachments: [%{filename: "hi.txt", content: Base.encode64("hi")}]
})

Summary

Functions

POST /emails/:id/cancel — only scheduled, unsent emails.

GET /emails/:id/insights — the email's deliverability insights report. Returns a "not_found" error until insights exist for the email.

GET /emails — accepts limit:, after:, before:.

POST /emails. Accepts an optional leading client and an optional idempotency_key: in the trailing options.

POST /emails/batch — 1..100 emails in one call. Options: idempotency_key: and batch_validation: (:strict, the default, or :permissive; sent as the x-batch-validation header).

PATCH /emails/:id — reschedule a scheduled, unsent email. params carries scheduled_at: (a map or keyword list).

Functions

cancel(client \\ MillionSend.client(), id)

@spec cancel(MillionSend.Client.t(), String.t()) ::
  {:ok, MillionSend.Emails.Email.t()} | {:error, MillionSend.Error.t()}

POST /emails/:id/cancel — only scheduled, unsent emails.

get(client \\ MillionSend.client(), id)

GET /emails/:id

get_insights(client \\ MillionSend.client(), id)

@spec get_insights(MillionSend.Client.t(), String.t()) ::
  {:ok, MillionSend.Emails.Insights.t()} | {:error, MillionSend.Error.t()}

GET /emails/:id/insights — the email's deliverability insights report. Returns a "not_found" error until insights exist for the email.

list()

GET /emails — accepts limit:, after:, before:.

list(client)

@spec list(MillionSend.Client.t() | keyword()) ::
  {:ok, MillionSend.List.t()} | {:error, MillionSend.Error.t()}

list(client, opts)

@spec list(
  MillionSend.Client.t(),
  keyword()
) :: {:ok, MillionSend.List.t()} | {:error, MillionSend.Error.t()}

remove(client \\ MillionSend.client(), id)

@spec remove(MillionSend.Client.t(), String.t()) ::
  {:ok, MillionSend.Emails.Email.t()} | {:error, MillionSend.Error.t()}

DELETE /emails/:id

send(params)

@spec send(map()) ::
  {:ok, MillionSend.Emails.Email.t()} | {:error, MillionSend.Error.t()}

POST /emails. Accepts an optional leading client and an optional idempotency_key: in the trailing options.

send(client, params)

@spec send(MillionSend.Client.t() | map(), map() | keyword()) ::
  {:ok, MillionSend.Emails.Email.t()} | {:error, MillionSend.Error.t()}

send(client, params, opts)

@spec send(MillionSend.Client.t(), map(), keyword()) ::
  {:ok, MillionSend.Emails.Email.t()} | {:error, MillionSend.Error.t()}

send_batch(list)

@spec send_batch([map()]) ::
  {:ok, [MillionSend.Emails.Email.t()]} | {:error, MillionSend.Error.t()}

POST /emails/batch — 1..100 emails in one call. Options: idempotency_key: and batch_validation: (:strict, the default, or :permissive; sent as the x-batch-validation header).

Strict mode is all-or-nothing and returns the accepted emails as a plain list. Permissive mode writes the valid subset and returns a MillionSend.Emails.BatchResponse whose errors lists the rejected items by request index.

send_batch(client, list)

@spec send_batch(MillionSend.Client.t() | [map()], [map()] | keyword()) ::
  {:ok, [MillionSend.Emails.Email.t()] | MillionSend.Emails.BatchResponse.t()}
  | {:error, MillionSend.Error.t()}

send_batch(client, list, opts)

update(client \\ MillionSend.client(), id, params)

@spec update(MillionSend.Client.t(), String.t(), map() | keyword()) ::
  {:ok, MillionSend.Emails.Email.t()} | {:error, MillionSend.Error.t()}

PATCH /emails/:id — reschedule a scheduled, unsent email. params carries scheduled_at: (a map or keyword list).