Class: Broadcast::DeliveryMethod
- Inherits:
-
Object
- Object
- Broadcast::DeliveryMethod
- Defined in:
- lib/broadcast/delivery_method.rb
Constant Summary collapse
- DEFAULT_INCLUDE_UNSUBSCRIBE_LINK =
ActionMailer delivers transactional mail, so the unsubscribe link is off unless the host app opts back in via broadcast_settings. The option is consumed here rather than forwarded: Configuration would reject it.
false
Instance Method Summary collapse
- #deliver!(mail) ⇒ Object
-
#initialize(settings = {}) ⇒ DeliveryMethod
constructor
A new instance of DeliveryMethod.
Constructor Details
#initialize(settings = {}) ⇒ DeliveryMethod
Returns a new instance of DeliveryMethod.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/broadcast/delivery_method.rb', line 10 def initialize(settings = {}) opts = settings.to_h.dup @include_unsubscribe_link = if opts.key?(:include_unsubscribe_link) opts.delete(:include_unsubscribe_link) else DEFAULT_INCLUDE_UNSUBSCRIBE_LINK end @client = Client.new(**opts) end |
Instance Method Details
#deliver!(mail) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/broadcast/delivery_method.rb', line 22 def deliver!(mail) @client.send_email( to: mail.to&.first, subject: mail.subject, body: extract_body(mail), reply_to: mail.reply_to&.first, html_body: (true if mail.html_part), include_unsubscribe_link: @include_unsubscribe_link ) rescue Broadcast::WarningError # The send succeeded — warnings_mode: :raise is about surfacing ignored # parameters, not reporting a delivery failure. Wrapping it in # DeliveryError would tell ActionMailer the mail didn't go out. raise rescue Broadcast::Error => e raise DeliveryError, "Failed to deliver email: #{e.}" end |