cultiv
(Sebastiaan Janssen)
February 23, 2025, 8:48am
9
Did you ever figure this one out? I have the same error, on the same line of code:
end
def sendgrid
if SiteSetting.sendgrid_verification_key.present?
return signature_failure if !valid_sendgrid_signature?
else
Rails.logger.warn(
"Received a Sendgrid webhook, but no verification key has been configured. This is unsafe behaviour and will be disallowed in the future.",
)
end
events = params["_json"] || [params]
events.each do |event|
message_id = Email::MessageIdService.message_id_clean((event["smtp-id"] || ""))
to_address = event["email"]
error_code = event["status"]
if event["event"] == "bounce"
# Sendgrid does not provide status field for emails that can't be delivered due to the recipient's server not existing
# so we set the error code to 5.1.2 which translates to permanent failure bad destination system address.
error_code = "5.1.2" if !error_code && event["type"] == "blocked"
I am not familiar with Ruby but it looks like it can parse the json just fiine up until trrying to parse the error code, Email::SMTP_STATUS_TRANSIENT_FAILURE points to:
I checked in Webhook.site what Sendgrid actually sends when I test the webhook and it looks like this for a bounce:
[
{
"email": "example@test.com",
"timestamp": 1740136261,
"smtp-id": "<14c5d75ce93.dfd.64b469@ismtpd-555>",
"event": "bounce",
"category": [
"cat facts"
],
"sg_event_id": "ovGQ2rRo8ytNezHPDq-7Ig==",
"sg_message_id": "14c5d75ce93.dfd.64b469.filter0001.16648.5515E0B88.0",
"reason": "500 unknown recipient",
"status": "5.0.0"
}
]
Seems like it should work!