bamboo v0.6.0 Bamboo.Mailer

Sets up mailers that make it easy to configure and swap adapters.

Adds deliver_now/1 and deliver_later/1 functions to the mailer module it is used by.

Bamboo ships with the following adapters

Example

# In your config/config.exs file
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_now/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_now
  end
end

Summary

Functions

Deliver an email in the background

Deliver an email right away

Wraps to, cc and bcc addresses in a list and normalizes email addresses

Functions

deliver_later(email)

Deliver an email in the background

Call your mailer with deliver_later/1 to send an email using the configured deliver_later_strategy. If no deliver_later_strategy is set, Bamboo.TaskSupervisorStrategy will be used. See Bamboo.DeliverLaterStrategy to learn how to change how emails are delivered with deliver_later/1.

deliver_now(email)

Deliver an email right away

Call your mailer with deliver_now/1 to send an email right away. Call deliver_later/1 if you want to send in the background to speed things up.

normalize_addresses(email)

Wraps to, cc and bcc addresses in a list and normalizes email addresses.

Also formats the from address. Email normalization/formatting is done by the [Bamboo.Formatter] protocol.