A wrapper for SendGrid's API to create composable emails.
Add the following code to your dependencies in your mix.exs
file:
{:sendgrid, "~> 1.0.1"}
In one of your configuration files, include your SendGrid API key like this:
config :sendgrid,
api_key: "SENDGRID_API_KEY"
If you'd like to enable sandbox mode (emails won't send but will be validated), add the setting to your config:
config :sendgrid,
api_key: "SENDGRID_API_KEY",
sandbox_enable: true
Add :sendgrid
to your list of applications
defp application do
[applications: [:sendgrid]]
end
Check the docs for complete usage.
alias SendGrid.{Mailer, Email}
email =
Email.build()
|> Email.put_from("[email protected]")
|> Email.put_to("[email protected]")
|> Email.put_subject("Hello From Elixir")
|> Email.put_text("Sent from Elixir!")
Mailer.send(email)
alias SendGrid.{Mailer, Email}
email =
Email.build()
|> Email.put_from("[email protected]")
|> Email.put_to("[email protected]")
|> Email.put_subject("Hello From Elixir")
|> Email.put_html("<html><body><p>Sent from Elixir!</p></body></html>")
Mailer.send(email)
alias SendGrid.{Mailer, Email}
email =
Email.build()
|> Email.put_template("the_template_id")
|> Email.add_substitution("-foo-", "bar")
|> Email.put_html("<span>Some Text</span>")
Mailer.send(email)