mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
DEV: Add bounce_error_code to EmailLog (#15948)
Whenever we got a bounced email in the Email::Receiver we previously would just set bounced: true on the EmailLog and discard the status/diagnostic code. This commit changes this flow to store the bounce error code (defined in the RFC at https://www.iana.org/assignments/smtp-enhanced-status-codes/smtp-enhanced-status-codes.xhtml) not just in the Email::Receiver, but also via webhook events from other mail services and from SNS. This commit does not surface the bounce error in the UI, we can do that later if necessary.
This commit is contained in:
@ -29,13 +29,16 @@ describe WebhooksController do
|
||||
"event" => "dropped",
|
||||
"recipient" => email,
|
||||
"Message-Id" => "<#{message_id}>",
|
||||
"signature" => signature
|
||||
"signature" => signature,
|
||||
"error" => "smtp; 550-5.1.1 The email account that you tried to reach does not exist.",
|
||||
"code" => "5.1.1"
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
email_log.reload
|
||||
expect(email_log.bounced).to eq(true)
|
||||
expect(email_log.bounce_error_code).to eq("5.1.1")
|
||||
expect(email_log.user.user_stat.bounce_score).to eq(SiteSetting.hard_bounce_score)
|
||||
end
|
||||
|
||||
@ -58,6 +61,11 @@ describe WebhooksController do
|
||||
"message-id" => message_id,
|
||||
}
|
||||
}
|
||||
},
|
||||
"delivery-status" => {
|
||||
"message" => "smtp; 550-5.1.1 The email account that you tried to reach does not exist.",
|
||||
"code" => "5.1.1",
|
||||
"description" => ""
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,6 +73,7 @@ describe WebhooksController do
|
||||
|
||||
email_log.reload
|
||||
expect(email_log.bounced).to eq(true)
|
||||
expect(email_log.bounce_error_code).to eq("5.1.1")
|
||||
expect(email_log.user.user_stat.bounce_score).to eq(SiteSetting.soft_bounce_score)
|
||||
end
|
||||
end
|
||||
@ -89,6 +98,7 @@ describe WebhooksController do
|
||||
|
||||
email_log.reload
|
||||
expect(email_log.bounced).to eq(true)
|
||||
expect(email_log.bounce_error_code).to eq("5.0.0")
|
||||
expect(email_log.user.user_stat.bounce_score).to eq(SiteSetting.hard_bounce_score)
|
||||
end
|
||||
end
|
||||
@ -109,6 +119,7 @@ describe WebhooksController do
|
||||
|
||||
email_log.reload
|
||||
expect(email_log.bounced).to eq(true)
|
||||
expect(email_log.bounce_error_code).to eq(nil) # mailjet doesn't give us this
|
||||
expect(email_log.user.user_stat.bounce_score).to eq(SiteSetting.hard_bounce_score)
|
||||
end
|
||||
end
|
||||
@ -123,6 +134,8 @@ describe WebhooksController do
|
||||
"event" => "hard_bounce",
|
||||
"msg" => {
|
||||
"email" => email,
|
||||
"diag" => "5.1.1",
|
||||
"bounce_description": "smtp; 550-5.1.1 The email account that you tried to reach does not exist.",
|
||||
"metadata" => {
|
||||
"message_id" => message_id
|
||||
}
|
||||
@ -134,6 +147,7 @@ describe WebhooksController do
|
||||
|
||||
email_log.reload
|
||||
expect(email_log.bounced).to eq(true)
|
||||
expect(email_log.bounce_error_code).to eq("5.1.1")
|
||||
expect(email_log.user.user_stat.bounce_score).to eq(SiteSetting.hard_bounce_score)
|
||||
end
|
||||
end
|
||||
@ -152,6 +166,7 @@ describe WebhooksController do
|
||||
|
||||
email_log.reload
|
||||
expect(email_log.bounced).to eq(true)
|
||||
expect(email_log.bounce_error_code).to eq(nil) # postmark doesn't give us this
|
||||
expect(email_log.user.user_stat.bounce_score).to eq(SiteSetting.hard_bounce_score)
|
||||
end
|
||||
it "soft bounces" do
|
||||
@ -167,6 +182,7 @@ describe WebhooksController do
|
||||
|
||||
email_log.reload
|
||||
expect(email_log.bounced).to eq(true)
|
||||
expect(email_log.bounce_error_code).to eq(nil) # postmark doesn't give us this
|
||||
expect(email_log.user.user_stat.bounce_score).to eq(SiteSetting.soft_bounce_score)
|
||||
end
|
||||
end
|
||||
@ -181,6 +197,7 @@ describe WebhooksController do
|
||||
"msys" => {
|
||||
"message_event" => {
|
||||
"bounce_class" => 10,
|
||||
"error_code" => "554",
|
||||
"rcpt_to" => email,
|
||||
"rcpt_meta" => {
|
||||
"message_id" => message_id
|
||||
|
Reference in New Issue
Block a user