diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb index ba091af0a0a..da681499fb0 100644 --- a/app/services/post_alerter.rb +++ b/app/services/post_alerter.rb @@ -719,6 +719,13 @@ class PostAlerter # email to the user who was just added by CC. In this case the OP probably # replied and CC'd some people, and they are the only other topic users. return if post.incoming_email.cc_addresses_split.include?(to_address) + + # We don't want to create an email storm if someone emails the group and + # CC's 50 support addresses from various places, which all then respond + # with auto-responders saying they have received our email. Any auto-generated + # emails should not propagate notifications to anyone else, not even + # the regular topic user notifications. + return email_addresses.dup.uniq if post.incoming_email.is_auto_generated? end # Send a single email using group SMTP settings to cut down on the diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb index ebcfd4ef51c..ddc26a448be 100644 --- a/spec/services/post_alerter_spec.rb +++ b/spec/services/post_alerter_spec.rb @@ -1710,6 +1710,16 @@ describe PostAlerter do ) end + it "does not send a group smtp email for anyone if the reply post originates from an incoming email that is auto generated" do + incoming_email_post = create_post_with_incoming + topic = incoming_email_post.topic + post = Fabricate(:post, topic: topic) + Fabricate(:incoming_email, post: post, topic: topic, is_auto_generated: true) + expect_not_enqueued_with(job: :group_smtp_email) do + expect { PostAlerter.new.after_save_post(post, true) }.to change { ActionMailer::Base.deliveries.size }.by(0) + end + end + it "skips sending a notification email to the group and all other email addresses that are _not_ members of the group, sends a group_smtp_email instead" do NotificationEmailer.enable