bamboo v0.3.2 Bamboo.Mailer
Sets up mailers that make it easy to configure and swap adapters.
Adds deliver/1 and deliver_later/1 functions to the mailer module it is used by. Bamboo ships with Bamboo.MandrillAdapter, Bamboo.LocalAdapter and Bamboo.TestAdapter.
Example
# In your config/config.exs file
# Other adapters that come with Bamboo are
# Bamboo.LocalAdapter and Bamboo.TestAdapter
config :my_app, MyApp.Mailer,
adapter: Bamboo.MandrillAdapter,
api_key: "my_api_key"
# Somewhere in your application. Maybe lib/my_app/mailer.ex
defmodule MyApp.Mailer do
# Adds deliver/1 and deliver_later/1
use Bamboo.Mailer, otp_app: :my_app
end
# Set up your emails
defmodule MyApp.Email do
import Bamboo.Email
def welcome_email do
new_mail(
to: "foo@example.com",
from: "me@example.com",
subject: "Welcome!!!",
html_body: "<strong>WELCOME</strong>",
text_body: "WELCOME"
)
end
end
# In a Phoenix controller or some other module
defmodule MyApp.Foo do
alias MyApp.Emails
alias MyApp.Mailer
def register_user do
# Create a user and whatever else is needed
# Could also have called Mailer.deliver_later
Email.welcome_email |> Mailer.deliver
end
end
Summary
Functions
Wraps to, cc and bcc addresses in a list and normalizes email addresses