aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionmailer/lib/action_mailer/base.rb')
-rw-r--r--actionmailer/lib/action_mailer/base.rb73
1 files changed, 50 insertions, 23 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index a8233512ab..e0a99fa00c 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -355,23 +355,32 @@ module ActionMailer #:nodoc:
alias :controller_path :mailer_name
class << self
- attr_writer :mailer_name
-
- delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::File, :prefix => :file
- delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::Sendmail, :prefix => :sendmail
- delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::Smtp, :prefix => :smtp
def mailer_name
@mailer_name ||= name.underscore
end
- alias :controller_path :mailer_name
+ attr_writer :mailer_name
- def delivery_method=(method_name)
- @delivery_method = ActionMailer::DeliveryMethod.lookup_method(method_name)
+ def delivery_settings
+ @delivery_settings ||= { :file => { :location => defined?(Rails.root) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails" },
+ :smtp => { :address => "localhost",
+ :port => 25,
+ :domain => 'localhost.localdomain',
+ :user_name => nil,
+ :password => nil,
+ :authentication => nil,
+ :enable_starttls_auto => true },
+ :sendmail => { :location => '/usr/sbin/sendmail',
+ :arguments => '-i -t' }
+ }
end
+ attr_writer :delivery_method
+
+ alias :controller_path :mailer_name
+
def respond_to?(method_symbol, include_private = false) #:nodoc:
- matches_dynamic_method?(method_symbol) || super
+ matches_dynamic_method?(method_symbol) || matches_settings_method?(method_symbol) || super
end
def method_missing(method_symbol, *parameters) #:nodoc:
@@ -382,6 +391,8 @@ module ActionMailer #:nodoc:
when 'new' then nil
else super
end
+ elsif match = matches_settings_method?(method_symbol)
+ delivery_settings[match[1].to_sym] = parameters[0]
else
super
end
@@ -413,7 +424,24 @@ module ActionMailer #:nodoc:
# email.set_some_obscure_header "frobnicate"
# MyMailer.deliver(email)
def deliver(mail)
- new.deliver!(mail)
+ raise "no mail object available for delivery!" unless mail
+
+ begin
+ ActiveSupport::Notifications.instrument("action_mailer.deliver",
+ :mailer => self.name) do |payload|
+ set_payload_for_mail(payload, mail)
+
+ mail.delivery_method delivery_method, get_delivery_settings(delivery_method)
+ if @@perform_deliveries
+ mail.deliver!
+ self.deliveries << mail
+ end
+ end
+ rescue Exception => e # Net::SMTP errors or sendmail pipe errors
+ raise e if raise_delivery_errors
+ end
+
+ mail
end
def template_root
@@ -437,6 +465,16 @@ module ActionMailer #:nodoc:
end
private
+
+ def get_delivery_settings(method) #:nodoc:
+ method.is_a?(Symbol) ? delivery_settings[method] : delivery_settings[:custom]
+ end
+
+ def matches_settings_method?(method_name) #:nodoc:
+ method_name = method_name.to_s
+ delivery_method.is_a?(Symbol) ? method = delivery_method : method = :custom
+ /(file|sendmail|smtp)_settings$/.match(method_name)
+ end
def matches_dynamic_method?(method_name) #:nodoc:
method_name = method_name.to_s
@@ -522,19 +560,7 @@ module ActionMailer #:nodoc:
# object (from the <tt>create!</tt> method). If no cached mail object exists, and
# no alternate has been given as the parameter, this will fail.
def deliver!(mail = @mail)
- raise "no mail object available for delivery!" unless mail
-
- begin
- ActiveSupport::Notifications.instrument("action_mailer.deliver",
- :template => template, :mailer => self.class.name) do |payload|
- self.class.set_payload_for_mail(payload, mail)
- self.delivery_method.perform_delivery(mail) if perform_deliveries
- end
- rescue Exception => e # Net::SMTP errors or sendmail pipe errors
- raise e if raise_delivery_errors
- end
-
- mail
+ self.class.deliver(mail)
end
private
@@ -566,6 +592,7 @@ module ActionMailer #:nodoc:
@mime_version ||= @@default_mime_version.dup if @@default_mime_version
@mailer_name ||= self.class.mailer_name.dup
+ @delivery_method = self.class.delivery_method
@template ||= method_name
@parts ||= []