Email Management with templating capability. The templates use Mustache template under the hood so you can do everything that the template system allow you to do.
def deps do
[
{:straw_hat_mailer, ">= 0.2.0"}
]
end
We need to setup Swoosh
adapter to be able to send the emails and the database
for save the templates.
# In your config files
config :straw_hat_mailer, StrawHat.Mailer,
adapter: Swoosh.Adapters.Sendgrid,
api_key: "SG.x.x"
config :straw_hat_mailer, StrawHat.Mailer.Repo,
adapter: Ecto.Adapters.Postgres,
database: "straw_hat_mailer",
hostname: "localhost",
username: "postgres",
password: "postgres"
StrawHat.Mailer use Swoosh
under the hood. The next example shows how to create
an email using specific template.
token = get_token()
from = {"ACME", "[email protected]"}
to = {"Straw Hat Team", "[email protected]"}
data = %{
confirmation_token: token
}
{:ok, email} =
from
|> StrawHat.Mailer.Email.new(to)
|> StrawHat.Mailer.Email.with_template("welcome", data)
StrawHat.Mailer.deliver(email)