Mandatory Email Headers or How to Send Email (into Spam)
First published on 2022-11-12.
Hey, It’s time to compose and send the first valid email message!
First of all, there are several mandatory headers and without any of them your email will be rejected:
MIME-Version- defines “how to parse” the thing you sent. It has a hardcoded value of1.0Content-Type- defines “how to read” the email you sent. Usually, values aretext/htmlortext/plain(andcharset="UTF-8", because we all ❤️ emojis)Content-Transfer-Encoding- kinda duplicate ofContent-Type’scharset, so value7bit== ASCII and value8bit== UnicodeFrom- defines the sender’s emailTo- defines the recipient’s emailMessage-Id- defines unique identification of that specific email, usually some random string +@your-server.com. Note the format:<random-string@server-address>(the<and>are mandatory)Date- defines “when it was sent” in RFC1123 with numeric zone format (go stdlib’stime.RFC1123Zformat:Mon, 02 Jan 2006 15:04:05 -0700)
Additionally, there are some headers, mandatory only in case of email threads (if you don’t provide them an email will be valid, but an email thread - will not):
In-Reply-To- definesMessage-Idof the previous email in a threadReferences- an array of allMessage-Ids in the thread
Here is an example of a fully valid email
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8BIT
From: your-email-sender@your-server.com
To: some@example.com
Message-Id: <some-random-string@your-server.com>
Date: Sat, 12 Nov 2022 19:13:27 +0000
Subject: A fully valid email example
That will go straight into the Spam dir of your mailbox!
(Un-)related posts about SMTP
A diary of a sweet summer child going insane and becoming a cynical Nolisting enjoyer.