Chat Summary emails are being skipped for users with a valid email:
I’ve done some analysis and I believe I know why:
Here’s ultimately where the skipping happens:
This is because message.to
is blank.
message.to
is blank because the arguments sent to send_user_email
do not include to_address
and this is never enriched with the user’s primary email, e.g.:
args: {"type"=>"chat_summary", "user_id"=>3, "force_respect_seen_recently"=>true, "current_site_id"=>"default"}
This is called by Chat Mailer, and you will notice that to_address
is missing:
and that is maybe fine, but by the time you get to the top of send_user_email
, I believe to_address
should be enriched with the user email so that when it is passed forward, the emailer is given access to this property and the emailing succeeds.
When I added this small monkey-patch to send_user_email
, the problem goes away:
# 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