Skip to content

Commit 425f1a3

Browse files
Add files via upload
1 parent 3b973f1 commit 425f1a3

File tree

100 files changed

+5590
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+5590
-0
lines changed

actionmailer/CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Rails 5.2.0.beta2 (November 28, 2017) ##
2+
3+
* No changes.
4+
5+
6+
## Rails 5.2.0.beta1 (November 27, 2017) ##
7+
8+
* Add `assert_enqueued_email_with` test helper.
9+
10+
assert_enqueued_email_with ContactMailer, :welcome do
11+
ContactMailer.welcome.deliver_later
12+
end
13+
14+
*Mikkel Malmberg*
15+
16+
* Allow Action Mailer classes to configure their delivery job.
17+
18+
class MyMailer < ApplicationMailer
19+
self.delivery_job = MyCustomDeliveryJob
20+
21+
...
22+
end
23+
24+
*Matthew Mongeau*
25+
26+
27+
Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/actionmailer/CHANGELOG.md) for previous changes.

actionmailer/MIT-LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright (c) 2004-2018 David Heinemeier Hansson
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+

actionmailer/README.rdoc

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
= Action Mailer -- Easy email delivery and testing
2+
3+
Action Mailer is a framework for designing email service layers. These layers
4+
are used to consolidate code for sending out forgotten passwords, welcome
5+
wishes on signup, invoices for billing, and any other use case that requires
6+
a written notification to either a person or another system.
7+
8+
Action Mailer is in essence a wrapper around Action Controller and the
9+
Mail gem. It provides a way to make emails using templates in the same
10+
way that Action Controller renders views using templates.
11+
12+
Additionally, an Action Mailer class can be used to process incoming email,
13+
such as allowing a blog to accept new posts from an email (which could even
14+
have been sent from a phone).
15+
16+
== Sending emails
17+
18+
The framework works by initializing any instance variables you want to be
19+
available in the email template, followed by a call to +mail+ to deliver
20+
the email.
21+
22+
This can be as simple as:
23+
24+
class Notifier < ActionMailer::Base
25+
default from: 'system@loudthinking.com'
26+
27+
def welcome(recipient)
28+
@recipient = recipient
29+
mail(to: recipient,
30+
subject: "[Signed up] Welcome #{recipient}")
31+
end
32+
end
33+
34+
The body of the email is created by using an Action View template (regular
35+
ERB) that has the instance variables that are declared in the mailer action.
36+
37+
So the corresponding body template for the method above could look like this:
38+
39+
Hello there,
40+
41+
Mr. <%= @recipient %>
42+
43+
Thank you for signing up!
44+
45+
If the recipient was given as "david@loudthinking.com", the email
46+
generated would look like this:
47+
48+
Date: Mon, 25 Jan 2010 22:48:09 +1100
49+
From: system@loudthinking.com
50+
To: david@loudthinking.com
51+
Message-ID: <4b5d84f9dd6a5_7380800b81ac29578@void.loudthinking.com.mail>
52+
Subject: [Signed up] Welcome david@loudthinking.com
53+
Mime-Version: 1.0
54+
Content-Type: text/plain;
55+
charset="US-ASCII";
56+
Content-Transfer-Encoding: 7bit
57+
58+
Hello there,
59+
60+
Mr. david@loudthinking.com
61+
62+
Thank you for signing up!
63+
64+
In order to send mails, you simply call the method and then call +deliver_now+ on the return value.
65+
66+
Calling the method returns a Mail Message object:
67+
68+
message = Notifier.welcome("david@loudthinking.com") # => Returns a Mail::Message object
69+
message.deliver_now # => delivers the email
70+
71+
Or you can just chain the methods together like:
72+
73+
Notifier.welcome("david@loudthinking.com").deliver_now # Creates the email and sends it immediately
74+
75+
== Setting defaults
76+
77+
It is possible to set default values that will be used in every method in your
78+
Action Mailer class. To implement this functionality, you just call the public
79+
class method +default+ which you get for free from <tt>ActionMailer::Base</tt>.
80+
This method accepts a Hash as the parameter. You can use any of the headers,
81+
email messages have, like +:from+ as the key. You can also pass in a string as
82+
the key, like "Content-Type", but Action Mailer does this out of the box for you,
83+
so you won't need to worry about that. Finally, it is also possible to pass in a
84+
Proc that will get evaluated when it is needed.
85+
86+
Note that every value you set with this method will get overwritten if you use the
87+
same key in your mailer method.
88+
89+
Example:
90+
91+
class AuthenticationMailer < ActionMailer::Base
92+
default from: "awesome@application.com", subject: Proc.new { "E-mail was generated at #{Time.now}" }
93+
.....
94+
end
95+
96+
== Receiving emails
97+
98+
To receive emails, you need to implement a public instance method called
99+
+receive+ that takes an email object as its single parameter. The Action Mailer
100+
framework has a corresponding class method, which is also called +receive+, that
101+
accepts a raw, unprocessed email as a string, which it then turns into the email
102+
object and calls the receive instance method.
103+
104+
Example:
105+
106+
class Mailman < ActionMailer::Base
107+
def receive(email)
108+
page = Page.find_by(address: email.to.first)
109+
page.emails.create(
110+
subject: email.subject, body: email.body
111+
)
112+
113+
if email.has_attachments?
114+
email.attachments.each do |attachment|
115+
page.attachments.create({
116+
file: attachment, description: email.subject
117+
})
118+
end
119+
end
120+
end
121+
end
122+
123+
This Mailman can be the target for Postfix or other MTAs. In Rails, you would use
124+
the runner in the trivial case like this:
125+
126+
rails runner 'Mailman.receive(STDIN.read)'
127+
128+
However, invoking Rails in the runner for each mail to be received is very
129+
resource intensive. A single instance of Rails should be run within a daemon, if
130+
it is going to process more than just a limited amount of email.
131+
132+
== Configuration
133+
134+
The Base class has the full list of configuration options. Here's an example:
135+
136+
ActionMailer::Base.smtp_settings = {
137+
address: 'smtp.yourserver.com', # default: localhost
138+
port: '25', # default: 25
139+
user_name: 'user',
140+
password: 'pass',
141+
authentication: :plain # :plain, :login or :cram_md5
142+
}
143+
144+
145+
== Download and installation
146+
147+
The latest version of Action Mailer can be installed with RubyGems:
148+
149+
$ gem install actionmailer
150+
151+
Source code can be downloaded as part of the Rails project on GitHub:
152+
153+
* https://github.com/rails/rails/tree/master/actionmailer
154+
155+
156+
== License
157+
158+
Action Mailer is released under the MIT license:
159+
160+
* https://opensource.org/licenses/MIT
161+
162+
163+
== Support
164+
165+
API documentation is at
166+
167+
* http://api.rubyonrails.org
168+
169+
Bug reports for the Ruby on Rails project can be filed here:
170+
171+
* https://github.com/rails/rails/issues
172+
173+
Feature requests should be discussed on the rails-core mailing list here:
174+
175+
* https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core

actionmailer/Rakefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require "rake/testtask"
4+
5+
desc "Default Task"
6+
task default: [ :test ]
7+
8+
task :package
9+
10+
# Run the unit tests
11+
Rake::TestTask.new { |t|
12+
t.libs << "test"
13+
t.pattern = "test/**/*_test.rb"
14+
t.warning = true
15+
t.verbose = true
16+
t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
17+
}
18+
19+
namespace :test do
20+
task :isolated do
21+
Dir.glob("test/**/*_test.rb").all? do |file|
22+
sh(Gem.ruby, "-w", "-Ilib:test", file)
23+
end || raise("Failures")
24+
end
25+
end

actionmailer/actionmailer.gemspec

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
version = File.read(File.expand_path("../RAILS_VERSION", __dir__)).strip
4+
5+
Gem::Specification.new do |s|
6+
s.platform = Gem::Platform::RUBY
7+
s.name = "actionmailer"
8+
s.version = version
9+
s.summary = "Email composition, delivery, and receiving framework (part of Rails)."
10+
s.description = "Email on Rails. Compose, deliver, receive, and test emails using the familiar controller/view pattern. First-class support for multipart email and attachments."
11+
12+
s.required_ruby_version = ">= 2.2.2"
13+
14+
s.license = "MIT"
15+
16+
s.author = "David Heinemeier Hansson"
17+
s.email = "david@loudthinking.com"
18+
s.homepage = "http://rubyonrails.org"
19+
20+
s.files = Dir["CHANGELOG.md", "README.rdoc", "MIT-LICENSE", "lib/**/*"]
21+
s.require_path = "lib"
22+
s.requirements << "none"
23+
24+
s.metadata = {
25+
"source_code_uri" => "https://github.com/rails/rails/tree/v#{version}/actionmailer",
26+
"changelog_uri" => "https://github.com/rails/rails/blob/v#{version}/actionmailer/CHANGELOG.md"
27+
}
28+
29+
s.add_dependency "actionpack", version
30+
s.add_dependency "actionview", version
31+
s.add_dependency "activejob", version
32+
33+
s.add_dependency "mail", ["~> 2.5", ">= 2.5.4"]
34+
s.add_dependency "rails-dom-testing", "~> 2.0"
35+
end

actionmailer/bin/test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
COMPONENT_ROOT = File.expand_path("..", __dir__)
5+
require_relative "../../tools/test"

actionmailer/lib/action_mailer.rb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# frozen_string_literal: true
2+
3+
#--
4+
# Copyright (c) 2004-2018 David Heinemeier Hansson
5+
#
6+
# Permission is hereby granted, free of charge, to any person obtaining
7+
# a copy of this software and associated documentation files (the
8+
# "Software"), to deal in the Software without restriction, including
9+
# without limitation the rights to use, copy, modify, merge, publish,
10+
# distribute, sublicense, and/or sell copies of the Software, and to
11+
# permit persons to whom the Software is furnished to do so, subject to
12+
# the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be
15+
# included in all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
#++
25+
26+
require "abstract_controller"
27+
require "action_mailer/version"
28+
29+
# Common Active Support usage in Action Mailer
30+
require "active_support"
31+
require "active_support/rails"
32+
require "active_support/core_ext/class"
33+
require "active_support/core_ext/module/attr_internal"
34+
require "active_support/core_ext/string/inflections"
35+
require "active_support/lazy_load_hooks"
36+
37+
module ActionMailer
38+
extend ::ActiveSupport::Autoload
39+
40+
eager_autoload do
41+
autoload :Collector
42+
end
43+
44+
autoload :Base
45+
autoload :DeliveryMethods
46+
autoload :InlinePreviewInterceptor
47+
autoload :MailHelper
48+
autoload :Parameterized
49+
autoload :Preview
50+
autoload :Previews, "action_mailer/preview"
51+
autoload :TestCase
52+
autoload :TestHelper
53+
autoload :MessageDelivery
54+
autoload :DeliveryJob
55+
end
56+
57+
autoload :Mime, "action_dispatch/http/mime_type"
58+
59+
ActiveSupport.on_load(:action_view) do
60+
ActionView::Base.default_formats ||= Mime::SET.symbols
61+
ActionView::Template::Types.delegate_to Mime
62+
end

0 commit comments

Comments
 (0)