Giter Club home page Giter Club logo

sendgrid-rails's Introduction

SendGrid gem provides ActionMailer::Base extensions to use SendGrid API features in you emails. It extends ActionMailer with next methods:

substitute(patters_string, array_of_substitunion_strings)
uniq_args(hash_of_unique_args)
category(category_string)
open_tracking(enabled = true)
add_filter_setting(filter_name, setting_name, value)

Rails 3 configuration

In your Gemfile:

gem 'sendgrid-rails', '~> 2.0'

In config/initializers/mail.rb:

ActionMailer::Base.register_interceptor(SendGrid::MailInterceptor)

ActionMailer::Base.smtp_settings = {
  :address => 'smtp.sendgrid.net',
  :port => '25',
  :domain => 'example.com',
  :authentication => :plain,
  :user_name => '[email protected]',
  :password => 'your password'
}

Usage examples

Adding multiple recipients:

class Mailer < ActionMailer::Base
  default :from => '[email protected]',
          :subject => 'An email sent via SendGrid'

  def email_with_multiple_recipients
    mail :to => %w([email protected] [email protected])
  end
end

Adding substitution vars

Mailer class definition:

class Mailer < ActionMailer::Base
  default :from => '[email protected]',
          :subject => 'An email sent via SendGrid with substitutions'

  def email_with_substitutions
    substitute '-user_name-', %w(User1 User2)

    mail :to => %w([email protected] [email protected]), :body => "Hello, -user_name-!"
  end
end

Adding category

Mailer class definition:

class Mailer < ActionMailer::Base
  default :from => '[email protected]',
          :subject => 'An email sent via SendGrid with substitutions'

  def email_with_category
    category 'SendGridRocks'
    mail :to => '[email protected]'
  end
end

Apps (formerly called Filters)

Apps can be applied to any of your email messages and can be configured through SendGrid gem.

Open Tracking

Add an invisible image at the end of the email to track e-mail opens. If the email recipient has images enabled on the email client, a request to server for the invisible image is executed and an open is logged.

class Mailer < ActionMailer::Base
  default :from => '[email protected]',
          :subject => 'An email sent via SendGrid'

  def email_with_open_tracking_enabled
    open_tracking true
    mail :to => '[email protected]'
  end
end

Change log

v2.0.2

  • ApiHeader#to_json wraps array items with spaces

v2.0.1

  • Standard SMTP To attribute set to ‘[email protected]’ after recipients added to X-SMTPAPI header

v2.0

  • Using mail interceptor

  • ActionMailer::Base#add_recipients - removed

  • Standard SMTP To attribute get nullified after recipients added to X-SMTPAPI header

sendgrid-rails's People

Contributors

gtd avatar nc avatar paveltyk avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.