mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FEATURE: add support for bounce emails
We now optionally add a Variable Email Return Path to every email we send. This allows us to cleanly handle email bounces, which in turn will improve deliverability.
This commit is contained in:
parent
9e25e4baa8
commit
fad017d842
5 changed files with 44 additions and 0 deletions
|
@ -818,6 +818,7 @@ en:
|
|||
title: "The name of this site, as used in the title tag."
|
||||
site_description: "Describe this site in one sentence, as used in the meta description tag."
|
||||
contact_email: "Email address of key contact responsible for this site. Used for critical notifications such as unhandled flags, as well as on the /about contact form for urgent matters."
|
||||
bounce_email: "Variable Email Return Path used for emails, example: bounce@example.com will cause us to generate bounce+GUID@example.com as the Retrun Path for emails we send. This feature allows us to automatically disable bouncing emails. Requires additional configurations, leave blank if unsure."
|
||||
contact_url: "Contact URL for this site. Used on the /about contact form for urgent matters."
|
||||
queue_jobs: "DEVELOPER ONLY! WARNING! By default, queue jobs in sidekiq. If disabled, your site will be broken."
|
||||
crawl_images: "Retrieve images from remote URLs to insert the correct width and height dimensions."
|
||||
|
|
|
@ -26,6 +26,10 @@ required:
|
|||
client: true
|
||||
default: ''
|
||||
type: email
|
||||
bounce_email:
|
||||
default: ''
|
||||
type: email
|
||||
shadowed_by_global: true
|
||||
contact_url:
|
||||
client: true
|
||||
default: ''
|
||||
|
|
5
db/migrate/20160418065403_add_bounce_key_to_email_log.rb
Normal file
5
db/migrate/20160418065403_add_bounce_key_to_email_log.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddBounceKeyToEmailLog < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :email_logs, :bounce_key, :string
|
||||
end
|
||||
end
|
|
@ -116,6 +116,18 @@ module Email
|
|||
@message.header['List-Post'] = "<mailto:#{email}>"
|
||||
end
|
||||
|
||||
unless SiteSetting.bounce_email.blank?
|
||||
email_log.bounce_key = SecureRandom.hex
|
||||
address,domain = SiteSetting.bounce_email.split('@')
|
||||
address << (address =~ /[+]/ ? "-" : '+')
|
||||
address << email_log.bounce_key
|
||||
|
||||
# WARNING: RFC claims you can not set the Return Path header, this is 100% correct
|
||||
# however Rails has special handling for this header and ends up using this value
|
||||
# as the Envelope From address so stuff works as expected
|
||||
@message.header[:return_path] = "#{address}@#{domain}"
|
||||
end
|
||||
|
||||
email_log.post_id = post_id if post_id.present?
|
||||
email_log.reply_key = reply_key if reply_key.present?
|
||||
|
||||
|
|
|
@ -77,6 +77,28 @@ describe Email::Sender do
|
|||
email_sender.send
|
||||
end
|
||||
|
||||
context "adds return_path correctly when no plus addressing" do
|
||||
before do
|
||||
SiteSetting.bounce_email = 'bounce@test.com'
|
||||
end
|
||||
|
||||
When { email_sender.send }
|
||||
Then {
|
||||
expect(message.header[:return_path].to_s).to eq("bounce+#{EmailLog.last.bounce_key}@test.com")
|
||||
}
|
||||
end
|
||||
|
||||
context "adds return_path correctly with plus addressing" do
|
||||
before do
|
||||
SiteSetting.bounce_email = 'bounce+meta@test.com'
|
||||
end
|
||||
|
||||
When { email_sender.send }
|
||||
Then {
|
||||
expect(message.header[:return_path].to_s).to eq("bounce+meta-#{EmailLog.last.bounce_key}@test.com")
|
||||
}
|
||||
end
|
||||
|
||||
context "adds a List-ID header to identify the forum" do
|
||||
before do
|
||||
category = Fabricate(:category, name: 'Name With Space')
|
||||
|
|
Loading…
Reference in a new issue