Repository is archived
No commit activity in last 3 years
No release in over 3 years
All this does is make the root_url and image_url available to a mailer subclass
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
>= 0
~> 10.0
>= 0

Runtime

 Project Readme

SparkpostMailer

This is a wrapper for the sparkpost gem. Just about everything here was a straight copy and paste from the mandrill_mailer gem. Since Mandrill charges now I switched to SparkPost and needed something to get what I had to work like the Mandrill setup.

Installation

Add this line to your application's Gemfile:

gem 'sparkpost_mailer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sparkpost_mailer

Usage

This is how I'm using it:

Initializer setup_mail.rb

ActionMailer::Base.smtp_settings = {
  :address   => "smtp.sparkpostmail.com",
  :port      => 587,
  :Encryption => "STARTTLS",
  :Authentication => "AUTH LOGIN",
  :User => "SMTP_Injection",
  :password  => ENV['SPARKPOST_API_KEY']
}
ActionMailer::Base.delivery_method = :smtp

SparkPostMailer.configure do |config|
  config.api_key = ENV['SPARKPOST_API_KEY']
end

application.rb

  config.sparkpost_mailer.default_url_options = { :host => "somehost.com" }

notification_mailer.rb

class NotificationMailer < SparkPostMailer::PayloadMailer

  def render(path)
      template = Tilt.new(path)
      template.render(self)
  end

  def added_to_project(user, project)
    @user = user
    @project = project
    payload = {
       recipients: [{ address: { email: @user.email } }],
       content: {
         from: "some_email@email.email",
         subject: "You've been added to a project",
         template_id: 'mailer_template_id'
       },
       substitution_data: {
         name: @user.name,
         LOGO: "#{image_url('ui/spark_logo.png')}",
         PAGETITLE: "This is an automated message from #{ActionMailer::Base.default_url_options[:host]}",
         PAGEBODY: render("app/views/notification_mailer/added_to_project.html.slim")
       }
     }
    response = self.deliver(payload)
    puts response
  end

end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/PSkaggs/sparkpost_mailer.

License

The gem is available as open source under the terms of the MIT License.