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!].
What needed to be done
message-idto all outgoing email as specified in Identification Fields:
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: <
- Write unit tests to verify that a
message-idis always present.
How I did it
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).
host_name: There is a
SMTPConfigobject which has all the SMTP config including host name. So, joining all these using
msgID := fmt.Sprintf("<%s-%d@%s>", model.NewRandomString(randomStringLength), time.Now().Unix(), config.Hostname)
- Test case: The was a test case which ensured that emails without
message-idare allowed. I just edited it to validate if every email has a
Have any questions/suggestions? leave a comment.
Never used mattermost? Give it a go.
Want to contribute like I did? Here's the repo.
Pull-request: Mm 46416 add default random message #21176
Did you find this article valuable?
Support Azanul Haque by becoming a sponsor. Any amount is appreciated!