Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounce emails can be sent with deliver_now #48446

Merged
merged 1 commit into from Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions actionmailbox/CHANGELOG.md
@@ -1,3 +1,7 @@
* Added `bounce_now_with` to send the bounce email without going through a mailer queue.

*Ronan Limon Duparcmeur*

* Support configured primary key types in generated migrations.

*Nishiki Liu*
Expand Down
7 changes: 6 additions & 1 deletion actionmailbox/lib/action_mailbox/base.rb
Expand Up @@ -101,13 +101,18 @@ def finished_processing? # :nodoc:
inbound_email.delivered? || inbound_email.bounced?
end


# Enqueues the given +message+ for delivery and changes the inbound email's status to +:bounced+.
def bounce_with(message)
inbound_email.bounced!
message.deliver_later
end

# Immediately sends the given +message+ and changes the inbound email's status to +:bounced+.
def bounce_now_with(message)
inbound_email.bounced!
message.deliver_now
end

private
def instrumentation_payload
{
Expand Down
23 changes: 23 additions & 0 deletions actionmailbox/test/unit/mailbox/bouncing_test.rb
Expand Up @@ -8,6 +8,12 @@ def process
end
end

class BouncingWithImmediateReplyMailbox < ActionMailbox::Base
def process
bounce_now_with BounceMailer.bounce(to: mail.from)
end
end

class ActionMailbox::Base::BouncingTest < ActiveSupport::TestCase
include ActionMailer::TestHelper

Expand All @@ -16,6 +22,10 @@ class ActionMailbox::Base::BouncingTest < ActiveSupport::TestCase
from: "sender@example.com", to: "replies@example.com", subject: "Bounce me"
end

teardown do
ActionMailer::Base.deliveries.clear
end

test "bouncing with a reply" do
perform_enqueued_jobs only: ActionMailer::MailDeliveryJob do
BouncingWithReplyMailbox.receive @inbound_email
Expand All @@ -28,4 +38,17 @@ class ActionMailbox::Base::BouncingTest < ActiveSupport::TestCase
assert_equal %w[ sender@example.com ], mail.to
assert_equal "Your email was not delivered", mail.subject
end

test "bouncing now with a reply" do
assert_no_enqueued_emails do
BouncingWithImmediateReplyMailbox.receive @inbound_email
end

assert @inbound_email.bounced?
assert_emails 1

mail = ActionMailer::Base.deliveries.last
assert_equal %w[ sender@example.com ], mail.to
assert_equal "Your email was not delivered", mail.subject
end
end