The discussion revolves around ensuring that every email generated by Discourse has a unique Message-ID, as required by RFC 2822. Currently, the same Message-ID is reused for multiple emails sent to different users for a single post, which could cause issues with email scanning gateways that reject duplicate Message-IDs with differing content. supermathie highlights this problem and suggests adding randomness to the Message-ID. zogstrip initially questions the severity but acknowledges the potential issue. mpalmer clarifies that the Message-ID should be unique per email, not per post. codinghorror proposes including the target user ID in the Message-ID for clarity, while supermathie suggests combining user ID with randomness. dan raises a concern about secondary emails, but codinghorror notes they are for login, not notifications. sam suggests that recent changes by @martin may have resolved the issue, as evidenced by a new Message-ID format.
The current IDs we generate are not unique - the same Message-ID will get used for every distinct email going out for a particular post (i.e. if it’s sent to 10 users, that Message-ID gets repeated 10 times):
if post.post_number == 1
"<topic/#{topic_id}@#{host}>"
else
"<topic/#{topic_id}/#{post.id}@#{host}>"
end
Message-ID: <topic/3981/53574@meta.discourse.org>
We should append some randomness onto the Message ID (which we can obviously remove when parsing incoming email).
I suspect it may be causing problems but am not entirely sure it is. 99.9% of the time things will be fine, but I know it would have caused problems at companies I’ve worked at previously (e.g. email scanning gateways may reject duplicate Message-IDs with different content).
Note the differing content comes from the post getting emailed to different people.
It really doesn’t need to make sense - “random string” is VERY typical.
If you want it to, I would do both - add the target user.id as well as random data (who knows - perhaps it’s possible now or in the future for the same user to be emailed about a post twice).
I am not exactly sure what’s up with the secondary emails feature, but if all of them are used to notify the user your approach may cause issues. If a user has multiple email addresses then it is going to receive multiple emails with the same Message-ID.