No commit activity in last 3 years
No release in over 3 years
Send batched Mails via Mandrill API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0
~> 3.0.0
>= 0

Runtime

 Project Readme

mandrill_batch_mailer

Code Coverage Build Status

Send batched Mails via Mandrill API.

Installation

gem install mandrill_batch_mailer

Configuration

# config/mandrill_batch_mailer.rb

MandrillBatchMailer.configure do |config|
  # enable sending mails via the Mandrill API, default is false
  config.perform_deliveries = true

  # Enables interception of mails. Default is false
  config.intercept_recipients = true

  # Set a mail address you want your mails redirected to. '+#{nr}' will be
  # added for each recipient and the subject line includes the original mail
  # address.
  config.interception_base_mail = 'all-mails-to@some-domain.com'

  # Set to your Mandrill API Key you get from Mandrill.
  config.api_key = '3x4mpl3_k3y'

  # Set your from e-mail address and name
  config.from_email = 'mail@my-app.com'
  config.from_name = 'My App'
end

Example

# config/locales/en.yml

en:
  mandrill:
    shared_translations:
      cheers: 'Cheers Your App-Team''
    welcome_mailer:
      welcome:
        subject: 'Welcome to our App!'
        welcome_to_app: 'welcome to our App.'
    mass_mailer:
      mass_mail:
        subject: 'This is a mass mail'
        be_awesome: 'let's be awesome!'

# app/mailers/mandrill/welcome_mailer.rb

class Mandrill::WelcomeMailer < MandrillBatchMailer::BaseMailer
  def welcome(user_id)
    @user = User.find user_id
    mail to: welcome_merge_vars
  end

  private

  def welcome_merge_vars
    {
      @user.email => {
        user_salutation: @user.salutation
      }
    }
  end
end

# app/mailers/mandrill/mass_mailer.rb

class Mandrill::MassMailer < MandrillBatchMailer::BaseMailer

  def mass_mail(user_ids)
    @users = User.find user_ids
    mail to: mass_mail_merge_vars
  end

  private

  def mass_mail_merge_vars
    @users.map do |user|
      [user.email,
        {
          user_salutation: user.salutation
        }
      ]
    end.to_h
  end
end