Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/sendgrid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def sendgrid_enable(*options)
self.default_sg_options = Array.new unless self.default_sg_options
options.each { |option| self.default_sg_options << option if VALID_OPTIONS.include?(option) }
end

# Sets the default text for subscription tracking (must be enabled).
# There are two options:
# 1. Add an unsubscribe link at the bottom of the email
Expand Down Expand Up @@ -98,6 +98,12 @@ def sendgrid_unique_args(unique_args = {})
end
end

# Call within mailer to set the asm_group_id for group unsubscribe tracking
# https://sendgrid.com/docs/API_Reference/SMTP_API/suppressions.html
def sendgrid_asm_group_id(asm_group_id)
@sg_asm_group_id = asm_group_id
end

# Call within mailer method to override the default value.
def sendgrid_category(category)
@sg_category = category
Expand Down Expand Up @@ -161,7 +167,7 @@ def sendgrid_ganalytics_options(options)
@ganalytics_options = []
options.each { |option| @ganalytics_options << option if VALID_GANALYTICS_OPTIONS.include?(option[0].to_sym) }
end

# only override the appropriate methods for the current ActionMailer version
if ActionMailer::Base.respond_to?(:mail)

Expand Down Expand Up @@ -206,7 +212,7 @@ def sendgrid_json_headers(mail)

#if not called within the mailer method, this will be nil so we default to empty hash
@sg_unique_args = @sg_unique_args || {}

# set the unique arguments
if @sg_unique_args || self.class.default_sg_unique_args
unique_args = self.class.default_sg_unique_args || {}
Expand All @@ -226,6 +232,9 @@ def sendgrid_json_headers(mail)
header_opts[:category] = self.class.default_sg_category
end

# Set asm_group_id if set by the user
header_opts[:asm_group_id] = @sg_asm_group_id unless @sg_asm_group_id.blank?

#Set send_at if set by the user
header_opts[:send_at] = @sg_send_at unless @sg_send_at.blank?

Expand Down