bamboo v1.3.0 Bamboo.Mailer View Source
Functions for delivering emails using adapters and delivery strategies.
Bamboo ships with several adapters. It is also possible to create your own adapter.
See the "Getting Started" section of the README for an example of how to set up and configure a mailer for use.
Creating a Mailer is as simple as defining a module in your application and
# some/path/within/your/app/mailer.ex defmodule MyApp.Mailer do use Bamboo.Mailer, otp_app: :my_app end
The mailer requires some configuration within your application.
# config/config.exs config :my_app, MyApp.Mailer, adapter: Bamboo.MandrillAdapter, # Specify your preferred adapter api_key: "my_api_key" # Specify adapter-specific configuration
Also you will want to define an email module for building email structs that
your mailer can send. See [
Bamboo.Email] for more information.
# some/path/within/your/app/email.ex defmodule MyApp.Email do import Bamboo.Email def welcome_email do new_email( to: "firstname.lastname@example.org", from: "email@example.com", subject: "Welcome to the app.", html_body: "<strong>Thanks for joining!</strong>", text_body: "Thanks for joining!" ) end end
You are now able to send emails with your mailer module where you sit fit within your application.
Link to this section Summary
Link to this section Functions
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
Deliver an email right away.
Pass in an argument of
response: true if you need access to the response
from delivering the email. This returns a tuple of the
deliver with your adapter. This is useful if you need
access to any data sent back from your email provider in the response.
Email.welcome_email |> Mailer.deliver_now(response: true)
Wraps to, cc and bcc addresses in a list and normalizes email addresses.
Also formats the from address. Email normalization/formatting is done by implementations of the [Bamboo.Formatter] protocol.