From 71f940d4787d0470100e177b3e39a14bfafa17c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Thu, 27 Oct 2016 19:35:50 +0200 Subject: [PATCH] FIX: use metadata to hold the message_id with sparkpost --- app/controllers/webhooks_controller.rb | 2 +- lib/email/sender.rb | 4 +++- spec/controllers/webhooks_controller_spec.rb | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/webhooks_controller.rb b/app/controllers/webhooks_controller.rb index 6292d5f1eb5..231329a7c67 100644 --- a/app/controllers/webhooks_controller.rb +++ b/app/controllers/webhooks_controller.rb @@ -91,7 +91,7 @@ class WebhooksController < ActionController::Base def sparkpost events = params["_json"] || [params] events.each do |event| - message_id = event["msys"]["message_event"]["message_id"] rescue nil + message_id = event["msys"]["message_event"]["rcpt_meta"]["message_id"] rescue nil bounce_class = event["msys"]["message_event"]["bounce_class"] rescue nil next unless message_id && bounce_class diff --git a/lib/email/sender.rb b/lib/email/sender.rb index d3774641820..087b8b8413b 100644 --- a/lib/email/sender.rb +++ b/lib/email/sender.rb @@ -133,12 +133,14 @@ module Email @message.header['X-Discourse-Post-Id'] = nil if post_id.present? @message.header['X-Discourse-Reply-Key'] = nil if reply_key.present? - # pass the original message_id when using mailjet/mandrill + # pass the original message_id when using mailjet/mandrill/sparkpost case ActionMailer::Base.smtp_settings[:address] when /\.mailjet\.com/ @message.header['X-MJ-CustomID'] = @message.message_id when "smtp.mandrillapp.com" @message.header['X-MC-Metadata'] = { message_id: @message.message_id }.to_json + when "smtp.sparkpostmail.com" + @message.header['X-MSYS-API'] = { metadata: { message_id: @message.message_id } }.to_json end # Suppress images from short emails diff --git a/spec/controllers/webhooks_controller_spec.rb b/spec/controllers/webhooks_controller_spec.rb index b77e363d831..6bf6404f315 100644 --- a/spec/controllers/webhooks_controller_spec.rb +++ b/spec/controllers/webhooks_controller_spec.rb @@ -109,7 +109,9 @@ describe WebhooksController do "msys" => { "message_event" => { "bounce_class" => 10, - "message_id" => message_id + "rcpt_meta" => { + "message_id" => message_id + } } } }]