Chat Summary 电子邮件被跳过,因为用户的电子邮件无效:
我做了一些分析,我认为我知道原因:
最终跳过的地方在这里:
这是因为 message.to 为空。
message.to 为空是因为传递给 send_user_email 的参数不包含 to_address,并且此参数从未用用户的首选电子邮件进行丰富,例如:
args: {"type"=>"chat_summary", "user_id"=>3, "force_respect_seen_recently"=>true, "current_site_id"=>"default"}
args[:type] = args[:type].to_s
send_user_email(args)
if args[:type] == "digest"
# Record every attempt at sending a digest email, even if it was skipped
UserStat.where(user_id: args[:user_id]).update_all(digest_attempted_at: Time.current)
end
end
def send_user_email(args)
post = nil
notification = nil
type = args[:type]
user = User.find_by(id: args[:user_id])
to_address =
args[:to_address].presence || user&.primary_email&.email.presence || "no_email_found"
set_skip_context(type, args[:user_id], to_address, args[:post_id])
return skip(SkippedEmailLog.reason_types[:user_email_no_user]) if !user
这是由 Chat Mailer 调用的,你会注意到 to_address 缺失:
return unless SiteSetting.chat_enabled
User
.real
.activated
.not_staged
.not_suspended
.where(id: users_with_unreads)
.find_each do |user|
if DiscoursePluginRegistry.apply_modifier(:chat_mailer_send_summary_to_user, true, user)
Jobs.enqueue(
:user_email,
type: "chat_summary",
user_id: user.id,
force_respect_seen_recently: true,
)
end
end
end
private
这也许没关系,但到你到达 send_user_email 的顶部时,我认为 to_address 应该用用户的电子邮件进行丰富,这样当它被传递下去时,邮件发送器就可以访问此属性,并且邮件发送会成功。
当我向 send_user_email 添加这个小的 monkey-patch 时,问题就消失了:
# CORE BUG: if we don't set to_address, ultimately the email won't send and will be skipped.
# This is a core bug and we will need to raise it on Meta.
if args[:to_address].blank? && user&.primary_email&.email
args[:to_address] = user&.primary_email&.email
end
2 个赞
sam
(Sam Saffron)
2025 年3 月 9 日 23:07
2
非常感谢 @merefield 的调试,我们会尽快让会员经验团队查看此问题。
2 个赞
davidb
(David B)
2025 年5 月 26 日 15:23
7
我对此进行了一些研究,如果我们沿着这条线索追溯,应该会有丰富的信息:
它从邮件发送器开始 此处 ,然后 调用用户通知扩展 ,该扩展 在此处 使用用户电子邮件进行丰富,然后将其传递给 此处 的构建电子邮件助手,最后在发送之前 此处 在消息构建器中设置地址。
除此之外,聊天摘要电子邮件已经在其他站点上运行,因此这里很可能还有其他原因导致了问题。
我认为一个临时的解决方案是将用户电子邮件传递给作业,这将使我们从一开始就更有信心/更清楚地了解是否存在正确的数据:
committed 03:19PM - 26 May 25 UTC
Pass user email rather than relying on enrichment when sending summary
emails.
3 个赞