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 Likes

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

1 Like

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 Likes

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

4 Likes

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

3 Likes

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 Likes

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

6 Likes

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 Likes

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 Likes

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

Eg:

Message ID	<topic/219646.66ed0fe487b002b5c60c3a6b@meta.discourse.org>
4 Likes