Sends email with the project sending token (x-lettermint-token).
Every function needs :sending_token on the client. Nothing about a
message is stored on the client: every call sends exactly what it is given.
lettermint = Lettermint.new(sending_token: System.fetch_env!("LETTERMINT_PROJECT_TOKEN"))
{:ok, result} =
Lettermint.Emails.send(lettermint, %{
from: "Acme <hello@acme.com>",
to: ["jane@example.com"],
subject: "Welcome",
html: "<p>Thanks for signing up.</p>"
}, idempotency_key: "welcome-jane")A message is a map in the API's field names (reply_to, scheduled_at,
sandbox_result, ...) with atom or string keys, or a
Lettermint.Types.SendMailRequest struct. For the pipe-friendly builder,
see compose/2 and Lettermint.EmailBuilder.
Attachments
An attachment is a map with :filename, :content, and optionally
:content_type and :content_id. content is base64 text, as the API
expects it, or {:bytes, binary} with the raw bytes, which the SDK
base64-encodes:
attachments: [
%{filename: "invoice.pdf", content: {:bytes, File.read!("invoice.pdf")}, content_type: "application/pdf"},
%{filename: "logo.png", content: logo_base64, content_id: "logo"}
]Tags
tags holds up to 20 name/value tags (19 when the legacy tag is also
set). Names match ^[A-Za-z0-9_-]{1,32}$, must not start with
__lettermint and must be unique (case-sensitive); values match
^[A-Za-z0-9_-]{1,64}$. The SDK checks this before the request and returns
Lettermint.ClientValidationError.
Summary
Types
An email: a map in the API's field names, or a SendMailRequest struct.
:idempotency_key (sent as Idempotency-Key) and :timeout (milliseconds).
Types
@type message() :: map() | Lettermint.Types.SendMailRequest.t()
An email: a map in the API's field names, or a SendMailRequest struct.
@type send_options() :: [idempotency_key: String.t(), timeout: pos_integer()]
:idempotency_key (sent as Idempotency-Key) and :timeout (milliseconds).
Functions
@spec compose(Lettermint.Client.t(), message() | nil) :: Lettermint.EmailBuilder.t()
Starts an immutable email builder. Pass a message to start from it.
Raises Lettermint.ConfigError when the client has no sending token, and
Lettermint.ClientValidationError when message is invalid.
@spec ping(Lettermint.Client.t(), [{:timeout, pos_integer()}]) :: {:ok, String.t()} | {:error, Lettermint.Error.t()}
Checks the sending token: GET /ping returns "pong".
@spec send(Lettermint.Client.t(), message(), send_options()) :: {:ok, Lettermint.Types.SendMailResponse.t()} | {:error, Lettermint.Error.t()}
Sends one email.
Options: :idempotency_key (retrying with the same key does not send the
email again) and :timeout in milliseconds.
@spec send_batch( Lettermint.Client.t(), [message() | Lettermint.EmailBuilder.t()], send_options() ) :: {:ok, Lettermint.Types.SendBatchMailResponse.t()} | {:error, Lettermint.Error.t()}
Sends up to 500 emails in one request. The list may mix messages and
builders. Takes the options of send/3.