Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for SendGrid custom parameters.

  • Loading branch information...
commit c3c7f99eb420ede23fecc63265e2f0d42fc61b8d 1 parent 58a10db
@marrrt marrrt authored
View
8 README.textile
@@ -61,9 +61,11 @@ class MyMailer < ActionMailer::Base
include SendGrid
sendgrid_category :use_subject_lines
sendgrid_enable :ganalytics, :opentracking
+ sendgrid_unique_args :key1 => "value1", :key2 => "value2"
def welcome_message(to_user)
sendgrid_category "Welcome"
+ sendgrid_unique_args :key2 => "newvalue2", :key3 => "value3"
recipients to_user.email
subject "Welcome :-)"
@@ -99,9 +101,13 @@ Here are a list of supported options for sendgrid_enable and sendgrid_disable:
** Call sendgrid_footer_text(:html => 'My HTML footer rocks!', :plain => 'My plain text footer is so-so.') to set custom footer text for html/plain or both.
* :spamcheck
** Call sendgrid_spamcheck_maxscore(4.5) to set a custom SpamAssassin threshold at which SendGrid drops emails (default value is 5.0).
-
+
For further explanation see "SendGrid's wiki page on filters.":http://wiki.sendgrid.com/doku.php?id=filters
+Custom parameters can be set using the sendgrid_unique_args methods. Any key/value pairs defined thusly will
+be included as parameters in SendGrid post backs. These are especially useful in cases where the recipient's
+email address is not unique or when multiple applications/environments are using the same SendGrid account.
+
h3. Delivering to multiple recipients
There is a per-mailer-method setting that can be used to deliver campaigns to multiple recipients at once. You should still set the "recipients" to an address per the normal ActionMailer usage, but it will not be used.
View
6 Rakefile
@@ -8,9 +8,9 @@ begin
gem.summary = %Q{A gem that allows simple integration of ActionMailer with SendGrid (http://sendgrid.com)}
gem.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.}
- gem.email = "stephenrb@gmail.com"
- gem.homepage = "http://github.com/stephenb/sendgrid"
- gem.authors = ["Stephen Blankenship"]
+ gem.email = "marc.tremblay@gmail.com"
+ gem.homepage = "http://github.com/pansapien/sendgrid"
+ gem.authors = ["Stephen Blankenship", "Marc Tremblay"]
# gem.add_development_dependency "thoughtbot-shoulda"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
View
2  VERSION
@@ -1 +1 @@
-0.1.4
+0.1.5
View
23 lib/sendgrid.rb
@@ -17,9 +17,10 @@ def self.included(base)
base.class_eval do
class << self
attr_accessor :default_sg_category, :default_sg_options, :default_subscriptiontrack_text,
- :default_footer_text, :default_spamcheck_score
+ :default_footer_text, :default_spamcheck_score, :default_sg_unique_args
end
- attr_accessor :sg_category, :sg_options, :sg_disabled_options, :sg_recipients, :sg_substitutions, :subscriptiontrack_text, :footer_text, :spamcheck_score
+ attr_accessor :sg_category, :sg_options, :sg_disabled_options, :sg_recipients, :sg_substitutions,
+ :subscriptiontrack_text, :footer_text, :spamcheck_score, :sg_unique_args
end
base.extend(ClassMethods)
end
@@ -72,12 +73,22 @@ def sendgrid_footer_text(texts)
def sendgrid_spamcheck_maxscore(score)
self.default_spamcheck_score = score
end
+
+ # Sets the default unique arguments to send
+ def sendgrid_unique_args(unique_args = {})
+ self.default_sg_unique_args = unique_args
+ end
end
# Call within mailer method to override the default value.
def sendgrid_category(category)
@sg_category = category
end
+
+ # Call within mailer method to add/override unique arguments in the defaults
+ def sendgrid_unique_args(unique_args = {})
+ @sg_unique_args = unique_args
+ end
# Call within mailer method to add an option not in the defaults.
def sendgrid_enable(*options)
@@ -138,6 +149,14 @@ def create!(method_name, *parameters)
def sendgrid_json_headers(mail)
header_opts = {}
+ # set the unique arguments
+ if @sg_unique_args || self.class.default_sg_unique_args
+ unique_args = self.class.default_sg_unique_args || {}
+ unique_args = unique_args.merge(@sg_unique_args)
+
+ header_opts[:unique_args] = unique_args
+ end
+
# Set category
if @sg_category && @sg_category == :use_subject_lines
header_opts[:category] = mail.subject
View
51 sendgrid.gemspec
@@ -0,0 +1,51 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{sendgrid}
+ s.version = "0.1.5"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Stephen Blankenship", "Marc Tremblay"]
+ s.date = %q{2010-09-11}
+ 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{marc.tremblay@gmail.com}
+ s.extra_rdoc_files = [
+ "LICENSE",
+ "README.textile"
+ ]
+ s.files = [
+ ".document",
+ ".gitignore",
+ "LICENSE",
+ "README.textile",
+ "Rakefile",
+ "VERSION",
+ "lib/sendgrid.rb",
+ "test/sendgrid_test.rb",
+ "test/test_helper.rb"
+ ]
+ s.homepage = %q{http://github.com/pansapien/sendgrid}
+ s.rdoc_options = ["--charset=UTF-8"]
+ 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"
+ ]
+
+ 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
+ else
+ end
+ else
+ end
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.