mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FEATURE: sendgrid webhooks
This commit is contained in:
parent
0f8b4dcc86
commit
9704603fab
7 changed files with 87 additions and 7 deletions
|
@ -37,6 +37,22 @@ class WebhooksController < ActionController::Base
|
|||
handled ? mailgun_success : mailgun_failure
|
||||
end
|
||||
|
||||
def sendgrid
|
||||
params["_json"].each do |event|
|
||||
if event["event"] == "bounce".freeze
|
||||
if event["status"]["4."]
|
||||
sendgrid_process(event, Email::Receiver::SOFT_BOUNCE_SCORE)
|
||||
else
|
||||
sendgrid_process(event, Email::Receiver::HARD_BOUNCE_SCORE)
|
||||
end
|
||||
elsif event["event"] == "dropped".freeze
|
||||
sendgrid_process(event, Email::Receiver::HARD_BOUNCE_SCORE)
|
||||
end
|
||||
end
|
||||
|
||||
render nothing: true, status: 200
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def mailgun_failure
|
||||
|
@ -74,4 +90,15 @@ class WebhooksController < ActionController::Base
|
|||
true
|
||||
end
|
||||
|
||||
def sendgrid_process(event, bounce_score)
|
||||
message_id = event["smtp-id"]
|
||||
return if message_id.blank?
|
||||
|
||||
email_log = EmailLog.find_by(message_id: message_id.tr("<>", ""))
|
||||
return if email_log.nil?
|
||||
|
||||
email_log.update_columns(bounced: true)
|
||||
Email::Receiver.update_bounce_score(email_log.user.email, bounce_score)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue