Letterbox.Email (Letterbox v0.1.0-rc.0)

Copy Markdown View Source

The email channel: a raw email as a Letterbox.Message (parse/2), and an email made from fields (build/1), for tests and the development page.

Summary

Functions

An email made from fields, as a mail client would write it: for tests, the development page, and an app's own ingress.

Reads a raw email (RFC 5322, as a mail server took it).

Functions

build(fields)

@spec build(keyword()) :: binary()

An email made from fields, as a mail client would write it: for tests, the development page, and an app's own ingress.

Letterbox.Email.build(
  from: "José Martínez <jose@example.com>",
  to: "photos+abc123@in.example.com",
  subject: "Férias",
  text: "Here they are.",
  attachments: [%{name: "praia.jpg", content_type: "image/jpeg", data: jpeg}]
)

Fields: :from, :to, :cc, :reply_to (an address or a list of them, as strings or Letterbox.Address), :subject, :text, :html, :attachments (maps or keywords of :name, :content_type, :data, and :content_id for one the HTML shows), :message_id, :in_reply_to, :references, :date (a DateTime, now by default), and :headers, a list of {name, value} more.

parse(raw, opts \\ [])

@spec parse(binary(), keyword()) :: Letterbox.Message.t()

Reads a raw email (RFC 5322, as a mail server took it).

Options:

  • :recipients - the addresses the mail server took it for (its envelope's RCPT TO), when the ingress knows them. They are the message's :recipients; without them, its To, Cc, Delivered-To and X-Original-To are.
  • :trusted_servers - the authserv-ids of the mail servers the app trusts to check senders (its provider's, its own), whose Authentication-Results give the message's :verified_from. Only a server that removes the headers others wrote in its name should be trusted (RFC 8601, section 5). None by default: no sender is verified.
  • :max_depth and :max_parts, as Letterbox.MIME.parse/2's.