Class: Railgun::Mailer
- Inherits:
-
Object
- Object
- Railgun::Mailer
- Defined in:
- lib/railgun/mailer.rb
Overview
Railgun::Mailer is an ActionMailer provider for sending mail through Mailgun.
Constant Summary collapse
- IGNORED_HEADERS =
List of the headers that will be ignored when copying headers from ‘mail.header_fields`
%w[ to from subject reply-to mime-version template ]
Instance Attribute Summary collapse
-
#config ⇒ Object
- Hash
-
config -> Requires *at least* ‘api_key` and `domain` keys.
-
#domain ⇒ Object
- Hash
-
config -> Requires *at least* ‘api_key` and `domain` keys.
-
#settings ⇒ Object
- Hash
-
config -> Requires *at least* ‘api_key` and `domain` keys.
Instance Method Summary collapse
- #deliver!(mail) ⇒ Object
-
#initialize(config) ⇒ Mailer
constructor
Initialize the Railgun mailer.
- #mailgun_client ⇒ Object
Constructor Details
#initialize(config) ⇒ Mailer
Initialize the Railgun mailer.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/railgun/mailer.rb', line 17 def initialize(config) @config = config [:api_key, :domain].each do |k| raise Railgun::ConfigurationError.new("Config requires `#{k}` key", @config) unless @config.has_key?(k) end @mg_client = Mailgun::Client.new( config[:api_key], config[:api_host] || 'api.mailgun.net', config[:api_version] || 'v3', config[:api_ssl].nil? ? true : config[:api_ssl], false, config[:timeout] ) @domain = @config[:domain] # To avoid exception in mail gem v2.6 @settings = { return_response: true } if (@config[:fake_message_send] || false) Rails.logger.info "NOTE: fake message sending has been enabled for mailgun-ruby!" @mg_client.enable_test_mode! end end |
Instance Attribute Details
#config ⇒ Object
- Hash
-
config ->
Requires *at least* `api_key` and `domain` keys.
12 13 14 |
# File 'lib/railgun/mailer.rb', line 12 def config @config end |
#domain ⇒ Object
- Hash
-
config ->
Requires *at least* `api_key` and `domain` keys.
12 13 14 |
# File 'lib/railgun/mailer.rb', line 12 def domain @domain end |
#settings ⇒ Object
- Hash
-
config ->
Requires *at least* `api_key` and `domain` keys.
12 13 14 |
# File 'lib/railgun/mailer.rb', line 12 def settings @settings end |
Instance Method Details
#deliver!(mail) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/railgun/mailer.rb', line 43 def deliver!(mail) @mg_domain = set_mg_domain(mail) @mg_client.set_api_key(mail[:api_key].value) if mail[:api_key].present? @mg_client.set_subaccount(mail[:subaccount_id].value) if mail[:subaccount_id].present? mail[:domain] = nil if mail[:domain].present? mail[:api_key] = nil if mail[:api_key].present? mail[:subaccount_id] = nil if mail[:subaccount_id].present? = Railgun.transform_for_mailgun(mail) response = @mg_client.(@mg_domain, ) if response.code == 200 then mg_id = response.to_h['id'] mail. = mg_id end response end |
#mailgun_client ⇒ Object
62 63 64 |
# File 'lib/railgun/mailer.rb', line 62 def mailgun_client @mg_client end |