mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08:00
FEATURE: Log the SMTP response in EmailLog (#17056)
When sending emails with delivery_method_options -> return_response set to true, the SMTP sending code inside Mail will return the SMTP response when calling deliver! for mail within the app. This commit ensures that Email::Sender captures this response if it is returned and stores it against the EmailLog created for the sent email. A follow up PR will make this visible within the admin email UI.
This commit is contained in:
@ -315,7 +315,13 @@ module Email
|
||||
DiscourseEvent.trigger(:before_email_send, @message, @email_type)
|
||||
|
||||
begin
|
||||
@message.deliver_now
|
||||
message_response = @message.deliver!
|
||||
|
||||
# TestMailer from the Mail gem does not return a real response, it
|
||||
# returns an array containing @message, so we have to have this workaround.
|
||||
if message_response.kind_of?(Net::SMTP::Response)
|
||||
email_log.smtp_transaction_response = message_response.message&.chomp
|
||||
end
|
||||
rescue *SMTP_CLIENT_ERRORS => e
|
||||
return skip(SkippedEmailLog.reason_types[:custom], custom_reason: e.message)
|
||||
end
|
||||
|
Reference in New Issue
Block a user