mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-24 15:33:57 -05:00
FEATURE: support for mandrill webhooks
This commit is contained in:
parent
95a013784f
commit
49f8a2baa7
4 changed files with 47 additions and 2 deletions
|
@ -71,6 +71,23 @@ class WebhooksController < ActionController::Base
|
||||||
render nothing: true, status: 200
|
render nothing: true, status: 200
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mandrill
|
||||||
|
events = params["mandrill_events"]
|
||||||
|
events.each do |event|
|
||||||
|
message_id = event["msg"]["metadata"]["message_id"] rescue nil
|
||||||
|
next unless message_id
|
||||||
|
|
||||||
|
case event["event"]
|
||||||
|
when "hard_bounce"
|
||||||
|
process_bounce(message_id, Email::Receiver::HARD_BOUNCE_SCORE)
|
||||||
|
when "soft_bounce"
|
||||||
|
process_bounce(message_id, Email::Receiver::SOFT_BOUNCE_SCORE)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
render nothing: true, status: 200
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def mailgun_failure
|
def mailgun_failure
|
||||||
|
|
|
@ -19,6 +19,7 @@ Discourse::Application.routes.draw do
|
||||||
post "webhooks/mailgun" => "webhooks#mailgun"
|
post "webhooks/mailgun" => "webhooks#mailgun"
|
||||||
post "webhooks/sendgrid" => "webhooks#sendgrid"
|
post "webhooks/sendgrid" => "webhooks#sendgrid"
|
||||||
post "webhooks/mailjet" => "webhooks#mailjet"
|
post "webhooks/mailjet" => "webhooks#mailjet"
|
||||||
|
post "webhooks/mandrill" => "webhooks#mandrill"
|
||||||
|
|
||||||
if Rails.env.development?
|
if Rails.env.development?
|
||||||
mount Sidekiq::Web => "/sidekiq"
|
mount Sidekiq::Web => "/sidekiq"
|
||||||
|
|
|
@ -133,9 +133,12 @@ module Email
|
||||||
@message.header['X-Discourse-Post-Id'] = nil if post_id.present?
|
@message.header['X-Discourse-Post-Id'] = nil if post_id.present?
|
||||||
@message.header['X-Discourse-Reply-Key'] = nil if reply_key.present?
|
@message.header['X-Discourse-Reply-Key'] = nil if reply_key.present?
|
||||||
|
|
||||||
# it's the only way to pass the original message_id when using mailjet
|
# pass the original message_id when using mailjet/mandrill
|
||||||
if ActionMailer::Base.smtp_settings[:address][".mailjet.com"]
|
case ActionMailer::Base.smtp_settings[:address]
|
||||||
|
when /\.mailjet\.com/
|
||||||
@message.header['X-MJ-CustomID'] = @message.message_id
|
@message.header['X-MJ-CustomID'] = @message.message_id
|
||||||
|
when "smtp.mandrillapp.com"
|
||||||
|
@message.header['X-MC-Metadata'] = { message_id: @message.message_id }.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
# Suppress images from short emails
|
# Suppress images from short emails
|
||||||
|
|
|
@ -75,4 +75,28 @@ describe WebhooksController do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "mandrill" do
|
||||||
|
|
||||||
|
it "works" do
|
||||||
|
user = Fabricate(:user, email: email)
|
||||||
|
email_log = Fabricate(:email_log, user: user, message_id: message_id)
|
||||||
|
|
||||||
|
post :mandrill, mandrill_events: [{
|
||||||
|
"event" => "hard_bounce",
|
||||||
|
"msg" => {
|
||||||
|
"metadata" => {
|
||||||
|
"message_id" => message_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
|
||||||
|
expect(response).to be_success
|
||||||
|
|
||||||
|
email_log.reload
|
||||||
|
expect(email_log.bounced).to eq(true)
|
||||||
|
expect(email_log.user.user_stat.bounce_score).to eq(2)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue