Mailtrap.Email (mailtrap v0.1.2)

Contains functions for composing email

Link to this section Summary

Functions

Puts attachments struct to the email struct

Puts blind carbon copy recepient or list of blind carbon copy recepients to the email struct

Puts category to the email struct

Puts carbon copy recepient or list of carbon copy recepients to the email struct

Puts custom_variables to the email struct.

Puts from field to the email

Puts headers to the email struct.

Puts html to the email struct

Puts subject to the email struct

Puts text to the email struct

Puts recepient or list of recepients to the email struct

Link to this section Types

@type address() :: {String.t(), String.t()}
Link to this type

address_list()

@type address_list() :: nil | address() | [address()] | any()
@type t() :: %Mailtrap.Email{
  attachments: nil | [Mailtrap.Email.Attachment.t(), ...],
  bcc: nil | [Mailtrap.Email.Mailbox.t(), ...],
  category: nil | String.t(),
  cc: nil | [Mailtrap.Email.Mailbox.t(), ...],
  custom_variables: nil | map(),
  from: nil | Mailtrap.Email.Mailbox.t(),
  headers: nil | map(),
  html: nil | String.t(),
  subject: nil | String.t(),
  text: nil | String.t(),
  to: nil | [Mailtrap.Email.Mailbox.t(), ...]
}

Link to this section Functions

Link to this function

put_attachments(email, attachments)

@spec put_attachments(t(), [Mailtrap.Email.Attachment.t(), ...]) :: t()

Puts attachments struct to the email struct

examples

Examples

iex> attachment = Mailtrap.Email.Attachment.build("content", "filename") iex> Mailtrap.Email.put_attachments(%Mailtrap.Email{}, [attachment]) %Mailtrap.Email{

attachments: [
  %Mailtrap.Email.Attachment{
    filename: "filename",
    content: "Y29udGVudA=="
  }
]

}

Link to this function

put_bcc(email, list)

@spec put_bcc(
  t(),
  {String.t() | nil, String.t()}
) :: t()
@spec put_bcc(t(), [tuple(), ...]) :: t()

Puts blind carbon copy recepient or list of blind carbon copy recepients to the email struct

examples

Examples

iex> Mailtrap.Email.put_bcc(%Mailtrap.Email{}, {"Jane", "jane.doe@example.org"}) %Mailtrap.Email{bcc: [%Mailtrap.Email.Mailbox{name: "Jane", email: "jane.doe@example.org"}]}

iex> Mailtrap.Email.put_bcc(%Mailtrap.Email{}, [{"Jane", "jane.doe@example.org"}, {"John", "john.doe@example.org"}]) %Mailtrap.Email{bcc: [%Mailtrap.Email.Mailbox{name: "Jane", email: "jane.doe@example.org"}, %Mailtrap.Email.Mailbox{name: "John", email: "john.doe@example.org"}]}

Link to this function

put_category(email, category)

@spec put_category(t(), String.t()) :: t()

Puts category to the email struct

examples

Examples

iex> Mailtrap.Email.put_category(%Mailtrap.Email{}, "Marketing") %Mailtrap.Email{category: "Marketing"}

Link to this function

put_cc(email, list)

@spec put_cc(
  t(),
  {String.t() | nil, String.t()}
) :: t()
@spec put_cc(t(), [tuple(), ...]) :: t()

Puts carbon copy recepient or list of carbon copy recepients to the email struct

examples

Examples

iex> Mailtrap.Email.put_cc(%Mailtrap.Email{}, {"Jane", "jane.doe@example.org"}) %Mailtrap.Email{cc: [%Mailtrap.Email.Mailbox{name: "Jane", email: "jane.doe@example.org"}]}

iex> Mailtrap.Email.put_cc(%Mailtrap.Email{}, [{"Jane", "jane.doe@example.org"}, {"John", "john.doe@example.org"}]) %Mailtrap.Email{cc: [%Mailtrap.Email.Mailbox{name: "Jane", email: "jane.doe@example.org"}, %Mailtrap.Email.Mailbox{name: "John", email: "john.doe@example.org"}]}

Link to this function

put_custom_variables(email, custom_variables)

@spec put_custom_variables(t(), map()) :: t()

Puts custom_variables to the email struct.

Values that are specific to the entire send that will be carried along with the email and its activity data. Total size of custom variables in JSON form must not exceed 1000 bytes.

examples

Examples

iex> Mailtrap.Email.put_custom_variables(%Mailtrap.Email{}, %{foo: "bar"}) %Mailtrap.Email{custom_variables: %{foo: "bar"}}

Link to this function

put_from(email, address)

@spec put_from(
  t(),
  {nil | String.t(), String.t()}
) :: t()

Puts from field to the email

examples

Examples

iex> Mailtrap.Email.put_from(%Mailtrap.Email{}, {"Jane", "jane.doe@example.org"}) %Mailtrap.Email{from: %Mailtrap.Email.Mailbox{name: "Jane", email: "jane.doe@example.org"}}

Link to this function

put_headers(email, headers)

@spec put_headers(t(), map()) :: t()

Puts headers to the email struct.

An object containing key/value pairs of header names and the value to substitute for them. The key/value pairs must be strings. You must ensure these are properly encoded if they contain unicode characters. These headers cannot be one of the reserved headers.

examples

Examples

iex> Mailtrap.Email.put_headers(%Mailtrap.Email{}, %{"X-Custom-Header" => "header-value"}) %Mailtrap.Email{headers: %{"X-Custom-Header" => "header-value"}}

Link to this function

put_html(email, html)

@spec put_html(t(), String.t()) :: t()

Puts html to the email struct

examples

Examples

iex> Mailtrap.Email.put_html(%Mailtrap.Email{}, "<strong>Hello, Jane</strong>") %Mailtrap.Email{html: "<strong>Hello, Jane</strong>"}

Link to this function

put_subject(email, subject)

@spec put_subject(t(), String.t()) :: t()

Puts subject to the email struct

examples

Examples

iex> Mailtrap.Email.put_subject(%Mailtrap.Email{}, "Hello") %Mailtrap.Email{subject: "Hello"}

Link to this function

put_text(email, text)

@spec put_text(t(), String.t()) :: t()

Puts text to the email struct

examples

Examples

iex> Mailtrap.Email.put_text(%Mailtrap.Email{}, "Hello, Jane") %Mailtrap.Email{text: "Hello, Jane"}

Link to this function

put_to(email, list)

@spec put_to(
  t(),
  {String.t() | nil, String.t()}
) :: t()
@spec put_to(t(), [tuple(), ...]) :: t()

Puts recepient or list of recepients to the email struct

examples

Examples

iex> Mailtrap.Email.put_to(%Mailtrap.Email{}, {"Jane", "jane.doe@example.org"}) %Mailtrap.Email{to: [%Mailtrap.Email.Mailbox{name: "Jane", email: "jane.doe@example.org"}]}

iex> Mailtrap.Email.put_to(%Mailtrap.Email{}, [{"Jane", "jane.doe@example.org"}, {"John", "john.doe@example.org"}]) %Mailtrap.Email{to: [%Mailtrap.Email.Mailbox{name: "Jane", email: "jane.doe@example.org"}, %Mailtrap.Email.Mailbox{name: "John", email: "john.doe@example.org"}]}