StrawHat.Mailer v0.4.4 StrawHat.Mailer.Email View Source

Add capability to create emails using templates.

token = get_token()
from = {"ACME", "noreply@acme.com"}
to = {"Straw Hat Team", "some_email@acme.com"}
data = %{
  confirmation_token: token
}

{:ok, email} =
  from
  |> StrawHat.Mailer.Email.new(to)
  |> StrawHat.Mailer.Email.with_template("welcome", data)

StrawHat.Mailer.deliver(email)

All your templates will receive the same shape of data which you could use mustache syntax for using it, read about StrawHat.Mailer.Email.template_data/0.

Link to this section Summary

Types

The tuple is compose by the name and email

You would use the data as mustache syntax does it using brackets. The partials key will whole all the partials of your template using name as the key so you will be able to use it as {{{partials.PARTIAL_NAME}}}. Notice I am using triple brackets and that is because probably you want to escape the output

Recipient or list of recipients of the email

Functions

Create a Swoosh.Email struct. It use Swoosh.Email.new/1 so you can check the Swoosh documentation, the only different is this one force you to pass from and to as paramters rather than inside the opts

Add subject, html and text to the Email using a template

Link to this section Types

The tuple is compose by the name and email.

Example: {"Straw Hat Team", "straw_hat_team@straw_hat.com"}

Link to this type template_data() View Source
template_data() :: %{
  data: struct(),
  partials: %{required(atom()) => String.t()},
  pre_header: String.t(),
  pre_header_html: String.t()
}

You would use the data as mustache syntax does it using brackets. The partials key will whole all the partials of your template using name as the key so you will be able to use it as {{{partials.PARTIAL_NAME}}}. Notice I am using triple brackets and that is because probably you want to escape the output.

Recipient or list of recipients of the email.

Link to this section Functions

Link to this function new(from, to, opts \\ []) View Source
new(address(), to(), keyword()) :: Swoosh.Email.t()

Create a Swoosh.Email struct. It use Swoosh.Email.new/1 so you can check the Swoosh documentation, the only different is this one force you to pass from and to as paramters rather than inside the opts.

Link to this function with_template(email, template_name_or_template_schema, data \\ %{}) View Source
with_template(
  Swoosh.Email.t(),
  StrawHat.Mailer.Schema.Template.t() | String.t(),
  map()
) :: {:ok, Swoosh.Email.t()} | {:error, StrawHat.Error.t()}

Add subject, html and text to the Email using a template.