Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
November 4, 2022 04:22 pm GMT

The case of missing message ID

Intro

This article assumes that you know how modern email works. Even if you don't, you'll get what the issue was and you also might get some idea by the end of this article. The title might seem unrelated but the issue occured when google MTAs stopped putting message
Emails sent by Mattermost (An opensource Slack alternative) were being marked as spam by many spam filters. This was happening because the emails were missing message-id which according to the Internet Message Format specification, is optional but still should be present [mixed signals!].

Section Divider

What needed to be done

a good method is to put the domain name (or a domain literal IP address) of the host on which the message identifier was created on the right-hand side of the "@" (since domain names and IP addresses are normally unique), and put a combination of the current absolute date and time along with some other currently unique (perhaps sequential) identifier available on the system (for example, a process id number) on the left-hand side.

simply, the format was going to be:
<unique_string-date_time@host_name>

  • Write unit tests to verify that a message-id is always present.

Section Divider

How I did it

  1. unique_string: A function was already written to generate a random string, so that's the one that I used. Although, a random string is not guaranteed to be unique as the same string can be generated again (the probability of repetition of a 16 char random string which has all 10 digits is ideally once out of 10^16).

  2. date-time: Used Go's time package to generate timestamp from current time object.

  3. host_name: There is a SMTPConfig object which has all the SMTP config including host name.
    So, joining all these using fmt.Sprintf:

msgID := fmt.Sprintf("<%s-%d@%s>", model.NewRandomString(randomStringLength), time.Now().Unix(), config.Hostname)
  1. Test case: The was a test case which ensured that emails without message-id are allowed. I just edited it to validate if every email has a message-id.

Section Divider

Next step

Section Divider

References

Footer


Original Link: https://dev.to/azanul/the-case-of-missing-message-id-n15

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To