class SendGrid::Mail
Attributes
asm[W]
attachments[R]
batch_id[RW]
categories[R]
contents[R]
custom_args[R]
from[W]
headers[R]
ip_pool_name[RW]
mail_settings[W]
personalizations[R]
reply_to[W]
sections[R]
send_at[RW]
subject[RW]
template_id[RW]
tracking_settings[W]
Public Class Methods
new(from_email = nil, subj = nil, to_email = nil, cont = nil)
click to toggle source
We allow for all nil values here to create uninitialized Mail
objects (e.g. <project-root>/use-cases/transactional-templates.md)
# File lib/sendgrid/helpers/mail/mail.rb, line 13 def initialize(from_email = nil, subj = nil, to_email = nil, cont = nil) # rubocop:disable Metrics/ParameterLists @from = nil @subject = nil @personalizations = [] @contents = [] @attachments = [] @template_id = nil @sections = {} @headers = {} @categories = [] @custom_args = {} @send_at = nil @batch_id = nil @asm = nil @ip_pool_name = nil @mail_settings = nil @tracking_settings = nil @reply_to = nil return if from_email.nil? && subj.nil? && to_email.nil? && cont.nil? self.from = from_email self.subject = subj personalization = Personalization.new personalization.add_to(to_email) add_personalization(personalization) add_content(cont) end
Public Instance Methods
add_attachment(attachment)
click to toggle source
# File lib/sendgrid/helpers/mail/mail.rb, line 61 def add_attachment(attachment) @attachments << attachment.to_json end
add_category(category)
click to toggle source
# File lib/sendgrid/helpers/mail/mail.rb, line 65 def add_category(category) @categories << category.name end
add_content(content)
click to toggle source
# File lib/sendgrid/helpers/mail/mail.rb, line 50 def add_content(content) @contents << content.to_json end
add_custom_arg(custom_arg)
click to toggle source
# File lib/sendgrid/helpers/mail/mail.rb, line 79 def add_custom_arg(custom_arg) custom_arg = custom_arg.to_json @custom_args = @custom_args.merge(custom_arg['custom_arg']) end
add_header(header)
click to toggle source
# File lib/sendgrid/helpers/mail/mail.rb, line 74 def add_header(header) header = header.to_json @headers = @headers.merge(header['header']) end
add_personalization(personalization)
click to toggle source
# File lib/sendgrid/helpers/mail/mail.rb, line 46 def add_personalization(personalization) @personalizations << personalization.to_json end
add_section(section)
click to toggle source
# File lib/sendgrid/helpers/mail/mail.rb, line 69 def add_section(section) section = section.to_json @sections = @sections.merge(section['section']) end
asm()
click to toggle source
# File lib/sendgrid/helpers/mail/mail.rb, line 84 def asm @asm.nil? ? nil : @asm.to_json end
check_for_secrets(patterns)
click to toggle source
# File lib/sendgrid/helpers/mail/mail.rb, line 54 def check_for_secrets(patterns) contents = @contents.map { |content| content['value'] }.join(' ') patterns.each do |pattern| raise SecurityError, 'Content contains sensitive information.' if contents.match(pattern) end end
from()
click to toggle source
# File lib/sendgrid/helpers/mail/mail.rb, line 42 def from @from.nil? ? nil : @from.to_json end
mail_settings()
click to toggle source
# File lib/sendgrid/helpers/mail/mail.rb, line 88 def mail_settings @mail_settings.nil? ? nil : @mail_settings.to_json end
reply_to()
click to toggle source
# File lib/sendgrid/helpers/mail/mail.rb, line 96 def reply_to @reply_to.nil? ? nil : @reply_to.to_json end
to_json(*)
click to toggle source
# File lib/sendgrid/helpers/mail/mail.rb, line 100 def to_json(*) { 'from' => from, 'subject' => subject, 'personalizations' => personalizations, 'content' => contents, 'attachments' => attachments, 'template_id' => template_id, 'sections' => sections, 'headers' => headers, 'categories' => categories, 'custom_args' => custom_args, 'send_at' => send_at, 'batch_id' => batch_id, 'asm' => asm, 'ip_pool_name' => ip_pool_name, 'mail_settings' => mail_settings, 'tracking_settings' => tracking_settings, 'reply_to' => reply_to }.delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {} } end
tracking_settings()
click to toggle source
# File lib/sendgrid/helpers/mail/mail.rb, line 92 def tracking_settings @tracking_settings.nil? ? nil : @tracking_settings.to_json end