Every email should have a unique Message-ID

Every single email that Discourse generates must have a unique Message-ID.

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

:arrow_down:

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).

4개의 좋아요

Does that cause any issues? I mean the message id is unique per “message”.

1개의 좋아요

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.

3개의 좋아요

This may explain an email issue I’ve been looking into.

4개의 좋아요

No, it’s unique per Discourse post. The “message” in an e-mail message ID is the e-mail.

3개의 좋아요

I know, I was half joking / half trolling :wink:

I didn’t know (think) about the email scanning gateway issue. I will get it fixed :ok_hand:

3개의 좋아요

I suggest appending the target user ID in the identifier, so the identifier actually makes sense versus “here’s a random string!”

6개의 좋아요

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).

4개의 좋아요

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.

I think they’re only used for login, not notifications.

3개의 좋아요

I feel like recent work by @martin has properly resolved this one?

Eg:

Message ID	<topic/219646.66ed0fe487b002b5c60c3a6b@meta.discourse.org>
4개의 좋아요