Skip to content
Browse files

Deprecate server_settings renaming it to smtp_settings, add sendmail_…

…settings to allow you to override the arguments to and location of the sendmail executable. [Koz]

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-stable@6094 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 7571380 commit 6744e35b25f79e2529e764a6d3d581b6d7dcd971 @NZKoz NZKoz committed Jan 31, 2007
Showing with 44 additions and 7 deletions.
  1. +4 −0 actionmailer/CHANGELOG
  2. +27 −7 actionmailer/lib/action_mailer/base.rb
  3. +13 −0 actionmailer/test/mail_service_test.rb
View
4 actionmailer/CHANGELOG
@@ -1,3 +1,7 @@
+*SVN*
+
+* Deprecate server_settings renaming it to smtp_settings, add sendmail_settings to allow you to override the arguments to and location of the sendmail executable. [Koz]
+
*1.3.1* (January 16th, 2007)
* Depend on Action Pack 1.13.1
View
34 actionmailer/lib/action_mailer/base.rb
@@ -184,7 +184,7 @@ module ActionMailer #:nodoc:
# * <tt>logger</tt> - the logger is used for generating information on the mailing run if available.
# Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
#
- # * <tt>server_settings</tt> - Allows detailed configuration of the server:
+ # * <tt>smtp_settings</tt> - Allows detailed configuration for :smtp delivery method:
# * <tt>:address</tt> Allows you to use a remote mail server. Just change it from its default "localhost" setting.
# * <tt>:port</tt> On the off chance that your mail server doesn't run on port 25, you can change it.
# * <tt>:domain</tt> If you need to specify a HELO domain, you can do it here.
@@ -193,10 +193,12 @@ module ActionMailer #:nodoc:
# * <tt>:authentication</tt> If your mail server requires authentication, you need to specify the authentication type here.
# This is a symbol and one of :plain, :login, :cram_md5
#
+ # * <tt>sendmail_settings</tt> - Allows you to override options for the :sendmail delivery method
+ # * <tt>:location</tt> The location of the sendmail executable, defaults to "/usr/sbin/sendmail"
+ # * <tt>:arguments</tt> The command line arguments
# * <tt>raise_delivery_errors</tt> - whether or not errors should be raised if the email fails to be delivered.
#
# * <tt>delivery_method</tt> - Defines a delivery method. Possible values are :smtp (default), :sendmail, and :test.
- # Sendmail is assumed to be present at "/usr/sbin/sendmail".
#
# * <tt>perform_deliveries</tt> - Determines whether deliver_* methods are actually carried out. By default they are,
# but this can be turned off to help functional testing.
@@ -228,15 +230,21 @@ class Base
class_inheritable_accessor :template_root
cattr_accessor :logger
- @@server_settings = {
+ @@smtp_settings = {
:address => "localhost",
:port => 25,
:domain => 'localhost.localdomain',
:user_name => nil,
:password => nil,
:authentication => nil
}
- cattr_accessor :server_settings
+ cattr_accessor :smtp_settings
+
+ @@sendmail_settings = {
+ :location => '/usr/sbin/sendmail',
+ :arguments => '-i -t'
+ }
+ cattr_accessor :sendmail_settings
@@raise_delivery_errors = true
cattr_accessor :raise_delivery_errors
@@ -355,6 +363,18 @@ def receive(raw_email)
def deliver(mail)
new.deliver!(mail)
end
+
+ # Server Settings is the old name for <tt>smtp_settings</tt>
+ def server_settings
+ smtp_settings
+ end
+ deprecate :server_settings=>"It's now named smtp_settings"
+
+ def server_settings=(settings)
+ ActiveSupport::Deprecation.warn("server_settings has been renamed smtp_settings, this warning will be removed with rails 2.0", caller)
+ self.smtp_settings=settings
+ end
+
end
# Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
@@ -542,14 +562,14 @@ def perform_delivery_smtp(mail)
destinations = mail.destinations
mail.ready_to_send
- Net::SMTP.start(server_settings[:address], server_settings[:port], server_settings[:domain],
- server_settings[:user_name], server_settings[:password], server_settings[:authentication]) do |smtp|
+ Net::SMTP.start(smtp_settings[:address], smtp_settings[:port], smtp_settings[:domain],
+ smtp_settings[:user_name], smtp_settings[:password], smtp_settings[:authentication]) do |smtp|
smtp.sendmail(mail.encoded, mail.from, destinations)
end
end
def perform_delivery_sendmail(mail)
- IO.popen("/usr/sbin/sendmail -i -t","w+") do |sm|
+ IO.popen("#{sendmail_settings[:location]} #{sendmail_settings[:arguments]}","w+") do |sm|
sm.print(mail.encoded.gsub(/\r/, ''))
sm.flush
end
View
13 actionmailer/test/mail_service_test.rb
@@ -787,6 +787,19 @@ def test_custom_content_type_attributes
assert_match %r{format=flowed}, mail['content-type'].to_s
assert_match %r{charset=utf-8}, mail['content-type'].to_s
end
+
+ def test_deprecated_server_settings
+ old_smtp_settings = ActionMailer::Base.smtp_settings
+ assert_deprecated do
+ ActionMailer::Base.server_settings
+ end
+ assert_deprecated do
+ ActionMailer::Base.server_settings={}
+ assert_equal Hash.new, ActionMailer::Base.smtp_settings
+ end
+ ensure
+ ActionMailer::Base.smtp_settings=old_smtp_settings
+ end
end
class InheritableTemplateRootTest < Test::Unit::TestCase

0 comments on commit 6744e35

Please sign in to comment.
Something went wrong with that request. Please try again.