Class: Cloudflare::Email::DeliveryMethod
- Inherits:
-
Object
- Object
- Cloudflare::Email::DeliveryMethod
- Defined in:
- lib/cloudflare/email/delivery_method.rb
Overview
ActionMailer delivery method. Registered on the :cloudflare symbol by the Engine.
Configure in your Rails app:
config.action_mailer.delivery_method = :cloudflare
config.action_mailer.cloudflare_settings = {
account_id: Rails.application.credentials.dig(:cloudflare, :account_id),
api_token: Rails.application.credentials.dig(:cloudflare, :api_token),
}
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
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.
17 18 19 |
# File 'lib/cloudflare/email/delivery_method.rb', line 17 def initialize(settings = {}) @settings = settings end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
15 16 17 |
# File 'lib/cloudflare/email/delivery_method.rb', line 15 def settings @settings end |
Instance Method Details
#deliver!(mail) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cloudflare/email/delivery_method.rb', line 21 def deliver!(mail) client = Cloudflare::Email::Client.new( account_id: settings.fetch(:account_id), api_token: settings.fetch(:api_token), base_url: settings[:base_url] || Cloudflare::Email::Client::DEFAULT_BASE_URL, retries: settings.fetch(:retries, Cloudflare::Email::Client::DEFAULT_RETRIES), timeout: settings.fetch(:timeout, Cloudflare::Email::Client::DEFAULT_TIMEOUT), logger: settings[:logger], ) from_addr = mail.from && mail.from.first recipients = collect_recipients(mail) raise Cloudflare::Email::ValidationError, "mail has no :from address" if from_addr.nil? raise Cloudflare::Email::ValidationError, "mail has no recipients" if recipients.empty? response = client.send_raw( from: from_addr, recipients: recipients, mime_message: mail.encoded, ) if response. && mail.respond_to?(:message_id=) mail. = response. end response end |