# `Letterbox.Email`
[🔗](https://github.com/hattoriai/letterbox/blob/v0.1.0-rc.0/lib/letterbox/email.ex#L1)

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.

# `build`

```elixir
@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`

```elixir
@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-id`s 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.

---

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