DEV: Add SMTP group ID to EmailLog (#13381)

Adds a new `smtp_group_id` column to `EmailLog` which is filled in if the mail `from_address` matches a group's `email_username`. This is for easier debugging, so we know which emails have been sent via group SMTP.
This commit is contained in:
Martin Brennan
2021-06-15 11:29:46 +10:00
committed by GitHub
parent 5f8f139ac9
commit 7fca7fb7ff
6 changed files with 73 additions and 19 deletions

View File

@ -97,6 +97,7 @@ module Email
post_id = header_value('X-Discourse-Post-Id')
topic_id = header_value('X-Discourse-Topic-Id')
reply_key = set_reply_key(post_id, user_id)
from_address = @message.from&.first
# always set a default Message ID from the host
@message.header['Message-ID'] = "<#{SecureRandom.uuid}@#{host}>"
@ -228,6 +229,12 @@ module Email
email_log.message_id = @message.message_id
# Log when a message is being sent from a group SMTP address, so we
# can debug deliverability issues.
if from_address && smtp_group_id = Group.where(email_username: from_address, smtp_enabled: true).pluck_first(:id)
email_log.smtp_group_id = smtp_group_id
end
DiscourseEvent.trigger(:before_email_send, @message, @email_type)
begin