Permalink
Browse files

Merge remote branch 'mikel/master'

  • Loading branch information...
2 parents 8974dac + c02391f commit abad097016bf5243e9812f6a031f421a986b09f7 @josevalim josevalim committed Jan 26, 2010
Showing with 2,054 additions and 1,270 deletions.
  1. +2 −0 actionmailer/CHANGELOG
  2. +39 −21 actionmailer/README
  3. +2 −2 actionmailer/Rakefile
  4. +1 −1 actionmailer/actionmailer.gemspec
  5. +4 −2 actionmailer/lib/action_mailer.rb
  6. +338 −404 actionmailer/lib/action_mailer/base.rb
  7. +36 −0 actionmailer/lib/action_mailer/collector.rb
  8. +0 −56 actionmailer/lib/action_mailer/delivery_method.rb
  9. +0 −21 actionmailer/lib/action_mailer/delivery_method/file.rb
  10. +0 −22 actionmailer/lib/action_mailer/delivery_method/sendmail.rb
  11. +0 −30 actionmailer/lib/action_mailer/delivery_method/smtp.rb
  12. +0 −12 actionmailer/lib/action_mailer/delivery_method/test.rb
  13. +87 −0 actionmailer/lib/action_mailer/delivery_methods.rb
  14. +112 −0 actionmailer/lib/action_mailer/deprecated_api.rb
  15. +0 −46 actionmailer/lib/action_mailer/deprecated_body.rb
  16. +6 −1 actionmailer/lib/action_mailer/mail_helper.rb
  17. +250 −0 actionmailer/lib/action_mailer/old_api.rb
  18. +1 −1 actionmailer/lib/action_mailer/test_case.rb
  19. +0 −1 actionmailer/lib/action_mailer/test_helper.rb
  20. +10 −2 actionmailer/lib/action_mailer/tmail_compat.rb
  21. +6 −19 actionmailer/test/abstract_unit.rb
  22. +420 −0 actionmailer/test/base_test.rb
  23. +0 −101 actionmailer/test/delivery_method_test.rb
  24. +170 −0 actionmailer/test/delivery_methods_test.rb
  25. +1 −0 actionmailer/test/fixtures/another.path/base_mailer/welcome.erb
  26. +1 −0 actionmailer/test/fixtures/base_mailer/attachment_with_content.erb
  27. +1 −0 actionmailer/test/fixtures/base_mailer/explicit_multipart_templates.html.erb
  28. +1 −0 actionmailer/test/fixtures/base_mailer/explicit_multipart_templates.text.erb
  29. +1 −0 actionmailer/test/fixtures/base_mailer/implicit_multipart.html.erb
  30. +1 −0 actionmailer/test/fixtures/base_mailer/implicit_multipart.text.erb
  31. +1 −0 actionmailer/test/fixtures/base_mailer/implicit_with_locale.en.html.erb
  32. +1 −0 actionmailer/test/fixtures/base_mailer/implicit_with_locale.html.erb
  33. +1 −0 actionmailer/test/fixtures/base_mailer/implicit_with_locale.pl.text.erb
  34. +1 −0 actionmailer/test/fixtures/base_mailer/implicit_with_locale.text.erb
  35. +1 −0 actionmailer/test/fixtures/base_mailer/welcome.erb
  36. +0 −1 actionmailer/test/fixtures/helper_mailer/use_example_helper.erb
  37. +0 −1 actionmailer/test/fixtures/helper_mailer/use_helper.erb
  38. +0 −1 actionmailer/test/fixtures/helper_mailer/use_helper_method.erb
  39. +0 −5 actionmailer/test/fixtures/helper_mailer/use_mail_helper.erb
  40. +0 −5 actionmailer/test/fixtures/helpers/example_helper.rb
  41. +0 −2 actionmailer/test/fixtures/test_mailer/body_ivar.erb
  42. +28 −70 actionmailer/test/mail_helper_test.rb
  43. +0 −24 actionmailer/test/mail_test.rb
  44. 0 actionmailer/test/{ → old_base}/adv_attr_test.rb
  45. +6 −8 actionmailer/test/{ → old_base}/asset_host_test.rb
  46. +22 −23 actionmailer/test/{ → old_base}/mail_layout_test.rb
  47. +33 −33 actionmailer/test/{ → old_base}/mail_render_test.rb
  48. +116 −139 actionmailer/test/{ → old_base}/mail_service_test.rb
  49. +9 −7 actionmailer/test/{ → old_base}/tmail_compat_test.rb
  50. +5 −3 actionmailer/test/{ → old_base}/url_test.rb
  51. +9 −9 actionmailer/test/subscriber_test.rb
  52. +13 −13 actionmailer/test/test_helper_test.rb
  53. +1 −0 actionpack/lib/abstract_controller.rb
  54. +30 −0 actionpack/lib/abstract_controller/collector.rb
  55. +0 −4 actionpack/lib/abstract_controller/rendering.rb
  56. +3 −26 actionpack/lib/action_controller/metal/mime_responds.rb
  57. +4 −0 actionpack/lib/action_controller/metal/rendering.rb
  58. +57 −0 actionpack/test/abstract/collector_test.rb
  59. +1 −0 activesupport/lib/active_support/core_ext/array.rb
  60. +0 −13 activesupport/lib/active_support/core_ext/array/conversions.rb
  61. +17 −0 activesupport/lib/active_support/core_ext/array/uniq_by.rb
  62. +6 −7 activesupport/lib/active_support/core_ext/hash/deep_merge.rb
  63. +6 −9 activesupport/lib/active_support/core_ext/hash/keys.rb
  64. +22 −18 activesupport/test/core_ext/array_ext_test.rb
  65. +1 −1 railties/lib/generators/erb/mailer/mailer_generator.rb
  66. +0 −3 railties/lib/generators/erb/mailer/templates/view.erb
  67. +3 −0 railties/lib/generators/erb/mailer/templates/view.text.erb
  68. +10 −9 railties/lib/generators/rails/mailer/templates/mailer.rb
  69. +2 −2 railties/lib/generators/rails/resource/resource_generator.rb
  70. +3 −3 railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb
  71. +1 −1 railties/lib/generators/test_unit/mailer/templates/fixture
  72. +5 −3 railties/lib/generators/test_unit/mailer/templates/functional_test.rb
  73. +34 −45 railties/lib/rails/generators/named_base.rb
  74. +23 −20 railties/lib/rails/generators/resource_helpers.rb
  75. +34 −5 railties/test/generators/mailer_generator_test.rb
  76. +55 −15 railties/test/generators/named_base_test.rb
View
@@ -1,5 +1,7 @@
*Rails 3.0 (pending)*
+* Whole new API added with tests. See base.rb for full details. Old API is deprecated.
+
* The Mail::Message class has helped methods for all the field types that return 'common' defaults for the common use case, so to get the subject, mail.subject will give you a string, mail.date will give you a DateTime object, mail.from will give you an array of address specs (mikel@test.lindsaar.net) etc. If you want to access the field object itself, call mail[:field_name] which will return the field object you want, which you can then chain, like mail[:from].formatted
* Mail#content_type now returns the content_type field as a string. If you want the mime type of a mail, then you call Mail#mime_type (eg, text/plain), if you want the parameters of the content type field, you call Mail#content_type_parameters which gives you a hash, eg {'format' => 'flowed', 'charset' => 'utf-8'}
View
@@ -5,51 +5,72 @@ are used to consolidate code for sending out forgotten passwords, welcome
wishes on signup, invoices for billing, and any other use case that requires
a written notification to either a person or another system.
+Action Mailer is in essence a wrapper around Action Controller and the
+Mail gem. It provides a way to make emails using templates in the same
+way that Action Controller renders views using templates.
+
Additionally, an Action Mailer class can be used to process incoming email,
such as allowing a weblog to accept new posts from an email (which could even
have been sent from a phone).
== Sending emails
-The framework works by setting up all the email details, except the body,
-in methods on the service layer. Subject, recipients, sender, and timestamp
-are all set up this way. An example of such a method:
+The framework works by initializing any instance variables you want to be
+available in the email template, followed by a call to +mail+ to deliver
+the email.
+
+This can be as simple as:
- def signed_up(recipient)
- recipients recipient
- subject "[Signed up] Welcome #{recipient}"
- from "system@loudthinking.com"
- body :recipient => recipient
+ class Notifier < ActionMailer::Base
+ delivers_from 'system@loudthinking.com'
+
+ def welcome(recipient)
+ @recipient = recipient
+ mail(:to => recipient,
+ :subject => "[Signed up] Welcome #{recipient}")
+ end
end
The body of the email is created by using an Action View template (regular
-ERb) that has the content of the body hash parameter available as instance variables.
+ERb) that has the instance variables that are declared in the mailer action.
+
So the corresponding body template for the method above could look like this:
Hello there,
Mr. <%= @recipient %>
+
+ Thank you for signing up!
And if the recipient was given as "david@loudthinking.com", the email
generated would look like this:
- Date: Sun, 12 Dec 2004 00:00:00 +0100
+ Date: Mon, 25 Jan 2010 22:48:09 +1100
From: system@loudthinking.com
To: david@loudthinking.com
+ Message-ID: <4b5d84f9dd6a5_7380800b81ac29578@void.loudthinking.com.mail>
Subject: [Signed up] Welcome david@loudthinking.com
+ Mime-Version: 1.0
+ Content-Type: text/plain;
+ charset="US-ASCII";
+ Content-Transfer-Encoding: 7bit
Hello there,
Mr. david@loudthinking.com
-You never actually call the instance methods like signed_up directly. Instead,
-you call class methods like deliver_* and create_* that are automatically
-created for each instance method. So if the signed_up method sat on
-ApplicationMailer, it would look like this:
+In previous version of rails you would call <tt>create_method_name</tt> and
+<tt>deliver_method_name</tt>. Rails 3.0 has a much simpler interface, you
+simply call the method and optionally call +deliver+ on the return value.
- ApplicationMailer.create_signed_up("david@loudthinking.com") # => tmail object for testing
- ApplicationMailer.deliver_signed_up("david@loudthinking.com") # sends the email
- ApplicationMailer.new.signed_up("david@loudthinking.com") # won't work!
+Calling the method returns a Mail Message object:
+
+ message = Notifier.welcome #=> Returns a Mail::Message object
+ message.deliver #=> delivers the email
+
+Or you can just chain the methods together like:
+
+ Notifier.welcome.deliver # Creates the email and sends it immediately
== Receiving emails
@@ -103,16 +124,13 @@ The Base class has the full list of configuration options. Here's an example:
Action Mailer requires that the Action Pack is either available to be required immediately
or is accessible as a GEM.
+Additionally, Action Mailer requires the Mail gem, http://github.com/mikel/mail
== Bundled software
-* tmail 0.10.8 by Minero Aoki released under LGPL
- Read more on http://i.loveruby.net/en/prog/tmail.html
-
* Text::Format 0.63 by Austin Ziegler released under OpenSource
Read more on http://www.halostatue.ca/ruby/Text__Format.html
-
== Download
The latest version of Action Mailer can be found at
View
@@ -22,14 +22,14 @@ task :default => [ :test ]
# Run the unit tests
Rake::TestTask.new { |t|
t.libs << "test"
- t.pattern = 'test/*_test.rb'
+ t.pattern = 'test/**/*_test.rb'
t.warning = true
}
namespace :test do
task :isolated do
ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
- Dir.glob("test/*_test.rb").all? do |file|
+ Dir.glob("test/**/*_test.rb").all? do |file|
system(ruby, '-Ilib:test', file)
end or raise "Failures"
end
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
s.homepage = "http://www.rubyonrails.org"
s.add_dependency('actionpack', '= 3.0.pre')
- s.add_dependency('mail', '~> 1.6.0')
+ s.add_dependency('mail', '~> 2.1.1')
s.files = Dir['CHANGELOG', 'README', 'MIT-LICENSE', 'lib/**/*']
s.has_rdoc = true
@@ -31,10 +31,12 @@ module ActionMailer
extend ::ActiveSupport::Autoload
autoload :AdvAttrAccessor
+ autoload :Collector
autoload :Base
- autoload :DeliveryMethod
- autoload :DeprecatedBody
+ autoload :DeliveryMethods
+ autoload :DeprecatedApi
autoload :MailHelper
+ autoload :OldApi
autoload :Quoting
autoload :TestCase
autoload :TestHelper
Oops, something went wrong.

2 comments on commit abad097

Contributor

dmathieu replied Jan 26, 2010

Yes ! :)
Thanks.

Member

mikel replied Jan 26, 2010

You are welcome :)

Please sign in to comment.