Class: Sendgrid::Mailer
- Inherits:
-
Object
- Object
- Sendgrid::Mailer
- Includes:
- SendGrid
- Defined in:
- lib/sendgrid/mailer.rb,
lib/sendgrid/mailer/version.rb
Constant Summary collapse
- VERSION =
"0.1.7"
Instance Method Summary collapse
- #build_mail_json(template_id:, to: nil, from: nil, bcc: nil, substitutions: {}, options: {}) ⇒ Object
-
#initialize(api_key, from, bcc, sandbox_mode: false, dev_catch_all:) ⇒ Mailer
constructor
A new instance of Mailer.
- #send_mail(options) ⇒ Object
Constructor Details
#initialize(api_key, from, bcc, sandbox_mode: false, dev_catch_all:) ⇒ Mailer
Returns a new instance of Mailer.
10 11 12 13 14 15 16 |
# File 'lib/sendgrid/mailer.rb', line 10 def initialize(api_key, from, bcc, sandbox_mode: false, dev_catch_all:) @api_key = api_key @from = from @bcc = bcc @sandbox_mode = sandbox_mode @dev_catch_all = dev_catch_all end |
Instance Method Details
#build_mail_json(template_id:, to: nil, from: nil, bcc: nil, substitutions: {}, options: {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sendgrid/mailer.rb', line 18 def build_mail_json(template_id:, to: nil, from: nil, bcc: nil, substitutions: {}, options: {}) = { force_send: false, }.merge() if @dev_catch_all to = @dev_catch_all end SendGrid::Mail.new.tap do |m| m.from = build_from(from) m.template_id = template_id if template_id m.personalizations = build_personalization(to, bcc, substitutions) if ![:force_send] && !Rails.env.production? m.mail_settings = SendGrid::MailSettings.new.tap do |s| s.sandbox_mode = SendGrid::SandBoxMode.new(enable: true) end end end.to_json end |
#send_mail(options) ⇒ Object
41 42 43 44 |
# File 'lib/sendgrid/mailer.rb', line 41 def send_mail() = build_mail_json() send_grid.client.mail._('send').post(request_body: ) end |