class Railgun::Mailer
Railgun::Mailer
is an ActionMailer provider for sending mail through Mailgun
.
Constants
- IGNORED_HEADERS
List of the headers that will be ignored when copying headers from `mail.header_fields`
Attributes
config[RW]
- Hash
-
config ->
Requires *at least* `api_key` and `domain` keys.
domain[RW]
- Hash
-
config ->
Requires *at least* `api_key` and `domain` keys.
settings[RW]
- Hash
-
config ->
Requires *at least* `api_key` and `domain` keys.
Public Class Methods
new(config)
click to toggle source
Initialize the Railgun
mailer.
@param [Hash] config Hash of config values, typically from `app_config.action_mailer.mailgun_config`
# File lib/railgun/mailer.rb, line 23 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
Public Instance Methods
deliver!(mail)
click to toggle source
# File lib/railgun/mailer.rb, line 49 def deliver!(mail) @mg_domain = set_mg_domain(mail) mail[:domain] = nil if mail[:domain].present? mg_message = Railgun.transform_for_mailgun(mail) response = @mg_client.send_message(@mg_domain, mg_message) if response.code == 200 then mg_id = response.to_h['id'] mail.message_id = mg_id end response end
mailgun_client()
click to toggle source
# File lib/railgun/mailer.rb, line 63 def mailgun_client @mg_client end
Private Instance Methods
set_mg_domain(mail)
click to toggle source
Set @mg_domain from mail header if present, then remove it to prevent being sent.
# File lib/railgun/mailer.rb, line 70 def set_mg_domain(mail) return mail[:domain].value if mail[:domain] domain end