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"}
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
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
.
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.