Skip to content

Commit

Permalink
Updated to support Rails 3's ActionMailer
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenb committed May 5, 2011
1 parent 10a7fc1 commit bad5afa
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Gemfile
@@ -0,0 +1,16 @@
source "http://rubygems.org"

gem "json"

# Add dependencies required to use your gem here.
# Example:
# gem "activesupport", ">= 2.3.5"

# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
# gem "shoulda", ">= 0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.1"
# gem "rcov", ">= 0"
end
18 changes: 18 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,18 @@
GEM
remote: http://rubygems.org/
specs:
git (1.2.5)
jeweler (1.5.2)
bundler (~> 1.0.0)
git (>= 1.2.5)
rake
json (1.5.1)
rake (0.8.7)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.0.0)
jeweler (~> 1.5.1)
json
2 changes: 2 additions & 0 deletions README.textile
Expand Up @@ -2,6 +2,8 @@ h1. sendgrid

h3. What is SendGrid?

* NOTE: Now updated to work with Rails 3! *

SendGrid is an awesome way to send large amounts of email (bells and whistles included) without spending large amounts of money. This gem allows for painless integration between ActionMailer and the SendGrid SMTP API. The current scope of this gem is focused around setting configuration options for outgoing email (essentially, setting categories, filters and the settings that can accompany those filters). SendGrid's service allows for some other cool stuff (such as postback notification of unsubscribes, bounces, etc.), but you'll have to integrate those features on your own.

Visit "SendGrid":http://sendgrid.com to learn more.
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -11,7 +11,7 @@ begin
gem.email = "stephenrb@gmail.com"
gem.homepage = "http://github.com/stephenb/sendgrid"
gem.authors = ["Stephen Blankenship"]
# gem.add_development_dependency "thoughtbot-shoulda"
gem.add_dependency "json"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
Expand Down
24 changes: 24 additions & 0 deletions lib/sendgrid.rb
Expand Up @@ -21,6 +21,14 @@ class << self
end
attr_accessor :sg_category, :sg_options, :sg_disabled_options, :sg_recipients, :sg_substitutions, :subscriptiontrack_text, :footer_text, :spamcheck_score
end

# NOTE: This commented-out approach may be a "safer" option for Rails 3, but it
# would cause the headers to get set during delivery, and not when the message is initialized.
# If base supports register_interceptor (i.e., Rails 3 ActionMailer), use it...
# if base.respond_to?(:register_interceptor)
# base.register_interceptor(SendgridInterceptor)
# end

base.extend(ClassMethods)
end

Expand Down Expand Up @@ -121,6 +129,7 @@ def sendgrid_spamcheck_maxscore(score)
end

# Sets the custom X-SMTPAPI header after creating the email but before delivery
# NOTE: This override is used for Rails 2 ActionMailer classes.
def create!(method_name, *parameters)
super
if @sg_substitutions && !@sg_substitutions.empty?
Expand All @@ -131,6 +140,21 @@ def create!(method_name, *parameters)
puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(mail)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
@mail['X-SMTPAPI'] = sendgrid_json_headers(mail)
end

protected

# Sets the custom X-SMTPAPI header after creating the email but before delivery
# NOTE: This override is used for Rails 3 ActionMailer classes.
def mail(headers={}, &block)
super
if @sg_substitutions && !@sg_substitutions.empty?
@sg_substitutions.each do |find, replace|
raise ArgumentError.new("Array for #{find} is not the same size as the recipient array") if replace.size != @sg_recipients.size
end
end
puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(message)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
self.headers['X-SMTPAPI'] = sendgrid_json_headers(message)
end

private

Expand Down
53 changes: 53 additions & 0 deletions sendgrid.gemspec
@@ -0,0 +1,53 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{sendgrid}
s.version = "0.1.4"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Stephen Blankenship"]
s.date = %q{2010-11-15}
s.description = %q{This gem allows simple integration between ActionMailer and SendGrid.
SendGrid is an email deliverability API that is affordable and has lots of bells and whistles.}
s.email = %q{stephenrb@gmail.com}
s.extra_rdoc_files = [
"LICENSE",
"README.textile"
]
s.files = [
".document",
"LICENSE",
"README.textile",
"Rakefile",
"VERSION",
"lib/sendgrid.rb",
"test/sendgrid_test.rb",
"test/test_helper.rb"
]
s.homepage = %q{http://github.com/stephenb/sendgrid}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.7}
s.summary = %q{A gem that allows simple integration of ActionMailer with SendGrid (http://sendgrid.com)}
s.test_files = [
"test/sendgrid_test.rb",
"test/test_helper.rb",
"test/test_mailers/kitchen_sink_mailer.rb"
]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<json>, [">= 0"])
else
s.add_dependency(%q<json>, [">= 0"])
end
else
s.add_dependency(%q<json>, [">= 0"])
end
end

0 comments on commit bad5afa

Please sign in to comment.