Skip to content

A platform for community discussion. Free, open, simple.

FIX: Strip Auto-Submitted email header from group SMTP emails (#15057)

Martin Brennan44be79f09526
diff --git a/lib/email/sender.rb b/lib/email/sender.rb
index f6547a42a35..cf2c98b2c08 100644
--- a/lib/email/sender.rb
+++ b/lib/email/sender.rb
@@ -213,9 +213,20 @@ module Email
@message.header[Email::MessageBuilder::ALLOW_REPLY_BY_EMAIL_HEADER] = nil
end
- # Replace reply_key in custom headers or remove
MessageBuilder.custom_headers(SiteSetting.email_custom_headers).each do |key, _|
value = header_value(key)
+
+ # Remove Auto-Submitted header for group private message emails, it does
+ # not make sense there and may hurt deliverability.
+ #
+ # From https://www.iana.org/assignments/auto-submitted-keywords/auto-submitted-keywords.xhtml:
+ #
+ # > Indicates that a message was generated by an automatic process, and is not a direct response to another message.
+ if key.downcase == "auto-submitted" && smtp_group_id
+ @message.header[key] = nil
+ end
+
+ # Replace reply_key in custom headers or remove
if value&.include?('%{reply_key}')
# Delete old header first or else the same header will be added twice
@message.header[key] = nil
diff --git a/spec/components/email/sender_spec.rb b/spec/components/email/sender_spec.rb
index 783b70c0507..eedb7e8ef49 100644
--- a/spec/components/email/sender_spec.rb
+++ b/spec/components/email/sender_spec.rb
@@ -414,6 +414,13 @@ describe Email::Sender do
expect(message.header['Precedence']).to eq(nil)
expect(message.header['List-Unsubscribe']).to eq(nil)
end
+
+ it "removes the Auto-Submitted header" do
+ TopicAllowedGroup.create!(topic: post.topic, group: group)
+ email_sender.send
+
+ expect(message.header['Auto-Submitted']).to eq(nil)
+ end
end
end