Skip to content

Commit e3f832a

Browse files
Deprecate ActionMailer::Base.receive in favor of Action Mailbox
1 parent 22a6ff6 commit e3f832a

File tree

5 files changed

+14
-40
lines changed

5 files changed

+14
-40
lines changed

actionmailer/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Deprecate `ActionMailer::Base.receive` in favor of [Action Mailbox](https://github.com/rails/rails/tree/master/actionmailbox).
2+
3+
*George Claghorn*
4+
15
* Add `MailDeliveryJob` for delivering both regular and parameterized mail. Deprecate using `DeliveryJob` and `Parameterized::DeliveryJob`.
26

37
*Gannon McGibbon*

actionmailer/README.rdoc

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -93,42 +93,6 @@ Example:
9393
.....
9494
end
9595

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-
13296
== Configuration
13397

13498
The Base class has the full list of configuration options. Here's an example:

actionmailer/actionmailer.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
66
s.platform = Gem::Platform::RUBY
77
s.name = "actionmailer"
88
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."
9+
s.summary = "Email composition and delivery framework (part of Rails)."
10+
s.description = "Email on Rails. Compose, deliver, and test emails using the familiar controller/view pattern. First-class support for multipart email and attachments."
1111

1212
s.required_ruby_version = ">= 2.5.0"
1313

actionmailer/lib/action_mailer/base.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,11 @@ def default(value = nil)
565565
# end
566566
# end
567567
def receive(raw_mail)
568+
ActiveSupport::Deprecation.warn(<<~MESSAGE.squish)
569+
ActionMailer::Base.receive is deprecated and will be removed in Rails 6.1.
570+
Use Action Mailbox to process inbound email.
571+
MESSAGE
572+
568573
ActiveSupport::Notifications.instrument("receive.action_mailer") do |payload|
569574
mail = Mail.new(raw_mail)
570575
set_payload_for_mail(payload, mail)

actionmailer/test/log_subscriber_test.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
require "abstract_unit"
44
require "mailers/base_mailer"
55
require "active_support/log_subscriber/test_helper"
6+
require "active_support/testing/stream"
67
require "action_mailer/log_subscriber"
78

89
class AMLogSubscriberTest < ActionMailer::TestCase
9-
include ActiveSupport::LogSubscriber::TestHelper
10+
include ActiveSupport::LogSubscriber::TestHelper, ActiveSupport::Testing::Stream
1011

1112
def setup
1213
super
@@ -53,7 +54,7 @@ def test_deliver_message_when_perform_deliveries_is_false
5354

5455
def test_receive_is_notified
5556
fixture = File.read(File.expand_path("fixtures/raw_email", __dir__))
56-
TestMailer.receive(fixture)
57+
silence_stream(STDERR) { TestMailer.receive(fixture) }
5758
wait
5859
assert_equal(1, @logger.logged(:info).size)
5960
assert_match(/Received mail/, @logger.logged(:info).first)

0 commit comments

Comments
 (0)