No commit activity in last 3 years
No release in over 3 years
Campaign Monitor transactional email adapter for ActionMailer
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 8.2.1
~> 1.25.1
= 3.3.0
>= 0
~> 3.0
= 0.37.2
~> 0.13.0

Runtime

>= 3.0.0
~> 5.0.0
 Project Readme

Campaign Monitor - Smart Transactional Emails for Rails

Build Status

The create_send_rails Gem drops into ActionMailer and sends transactional emails via the Campaign Monitor API, using its Smart Email feature.

It updates ActionMailer so it defaults to JSON mailer views and allows you to define the data required for each of your mailers.

Getting Started

To get started, add the following line to your applications Gemfile:

gem 'createsend-rails'

Then update your environment files and set delivery_method to create_send and include your CampaignMonitor api_key within the settings block.

config.action_mailer.delivery_method = :create_send
config.action_mailer.create_send_settings = {
    api_key: 'INSERT_API_KEY'
}

Once that's done, you can create a simple example Mailer :

class UserMailer < ApplicationMailer
  def user_registered
    @user = params[:user]
    mail to: @user.email
  end
end

Now go into your views/user_mailer/ and add a user_registered.json.erb view, which defines the data attributes required by your Smart Email template. Below is an example of a user activation email. Here, @user references the instance variable of the UserMailer we created.

{
    "smart_email_id": "SMART_EMAIL_ID",
    "consent_to_track: "yes/no/unchanged",
    "language": "<%= @user.language %>",
    "name": "<%= @user.name %>",
    "token": "<%= @user.confirmation_token %>"
}

You can now trigger the email from anywhere you want, for example in an after_create callback on your User model :

  class User < ApplicationRecord 
    after_create :send_activation_mail
    ...

    def send_activation_mail # The user we pass with the method 'with' is the one we receive in the mailer through params[:user]
      UserMailer.with(user: self).user_registered.deliver_later
    end
  end

Credits

made

Initialy developed by Made Tech Ltd. Key contributions:

License

It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.