Skip to content
This repository has been archived by the owner on Dec 30, 2019. It is now read-only.

Ability to use an yml file with separate smtp settings for ar_sendmail #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/action_mailer/ar_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ def self.email_class=(klass)
def self.email_class
@@email_class_name.constantize
end

##
# Set the name of the yml config file for smtp.
#
@@smtp_settings_path_name = "#{Rails.root}/config/smtp_settings.yml"

def self.smtp_settings_path=(filename)
@@smtp_settings_path_name = filename
end

def self.smtp_settings_path
@@smtp_settings_path_name
end

##
# Adds +mail+ to the Email table. Only the first From address for +mail+ is
Expand Down
16 changes: 13 additions & 3 deletions lib/action_mailer/ar_sendmail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def deliver(emails)
else
settings << smtp_settings[:tls]
end

smtp.start(*settings) do |session|
@failed_auth_count = 0
until emails.empty? do
Expand Down Expand Up @@ -468,15 +468,25 @@ def run
end

##
# Proxy to ActionMailer::Base::smtp_settings. See
# Either settings loaded from smtp settings file or
# proxy to ActionMailer::Base::smtp_settings. See
# http://api.rubyonrails.org/classes/ActionMailer/Base.html
# for instructions on how to configure ActionMailer's SMTP server.
#
# Falls back to ::server_settings if ::smtp_settings doesn't exist for
# backwards compatibility.

def smtp_settings
ActionMailer::Base.smtp_settings rescue ActionMailer::Base.server_settings
@smtp_settings ||= begin
if File.exists?(ActionMailer::Base.smtp_settings_path)
config = YAML::load_file(ActionMailer::Base.smtp_settings_path)
config = (config.has_key?(Rails.env) ? config[Rails.env] : config).with_indifferent_access
config[:authentication] = config[:authentication].to_sym if config[:authentication]
config
else
ActionMailer::Base.smtp_settings rescue ActionMailer::Base.server_settings
end
end
end

end