A Bit about Email

Hacker News by 18 min read 11x views
A Bit about Email

Share Post

2026-11-06 — 2026-11-08 Before you torch and pitchfork me, I'm conscious most of this is simplified and doesn't go into border cases, equal although the net is composed entirely of border cases. Otherwise, I'd be penning a entire book.

First, several terminology; A representative email volition former through many distinct components on the way to the recipient:

 1. Sender's MUA [Via SMTP on harbor 465] 2. Sending MSA 3. Sending MTA [Via SMTP on harbor 25] 4. Receiving MTA 5. Receiving LDA and communication store [Via IMAP] 7. Receiver's MUA 

(These aren't all necessarily distinct machines or equal distinct programs, but it is helpful to name all step.)

The communication person delegate (MUA) runs on the user's device and is what they use to dispatch or peruse messages. Let's say they dispatch something: that communication volition be uploaded to to the submission delegate (MSA) which checks the user's password before handing off to the communication transfer delegate (MTA).

The transfer agent's job is to conversation to another communication servers and get the communication to the receiving side's MTA. Once received, it's stated to the local shipment delegate (LDA) to be stored until the recipient checks their email. The name "LDA" is non-standard, but I use it to evade having four distinct abbreviations differing by a sole letter.

The logic for this structure is that whenever the scheme was being designed (around 1980), most organizations could lone oversee a sole server. Maintenance was a complete period job and updates frequently required multiple days of downtime. A well-connected device power have dedicated single-digits megabit/second nexus that worked fractional the time.

This forced the MTA and MUA distinction: if the recipient's server isn't up whenever the email is set, the sending MTA volition preserve the communication and re-attempt shipment later. This way, abbreviated outages don't logic bounced mail. Since the communication client is an interactive program the person runs, a distinct communication shop is needed to keep the email until it can be read.

Most MTAs are configured to continue retrying a communication for five days, normally alongside exponential backoff: mine volition delay 5 minutes following the archetypal failure, and addition the duration to one hr in prolonged outages.

The MSA and LDA have continually existed in several capacity, but have gotten a lot additional complicated when group started accessing email from their own computers alternatively or remotely logging onto a server.

SMTP

Most communication happens complete the Simple Mail Transfer Protocol, including MTA-MTA delivery. To narrow it downward a bit, I'll feign do be an MTA sending email to [email protected].

The archetypal stage is to appearance up the receiving MTA for that domain:

 # dig MX maurycyz.com [snip] maurycyz.com. 300 IN MX 1 smallcrow.com. [snip] # dig A smallcrow.com [snip] smallcrow.com. 300 IN A 65.109.172.162 [snip] 

Email is old adequate to have it's own dedicated DNS document alternatively of using subdomain hacks or TXT abuse. The figure is a precedence (smaller is higher), which is used if multiple hosts are specified: a big email provider volition have multiple servers to justify timely delivery.

SMTP is a comparatively straightforward content based protocol. The one capture is that most communication servers volition necessitate a CRLF as a data terminator. This can frequently be sent alongside ctrl-m, but using a tool that automatically inserts cartridge-return bytes is easier:

 # telnet telnet> set crlf Will dispatch wagon returns as telnet <CR><LF>. telnet> open smallcrow.com 25 Trying 65.109.172.162... Connected to smallcrow.com. Escape character is '^]'. 220 smallcrow.com ESMTP Postfix HELO nowhere 250 smallcrow.com MAIL FROM:<me@nowhere> 250 2.1.0 Ok RCPT TO:<[email protected]> 250 2.1.5 Ok DATA 354 End data alongside <CR><LF>.<CR><LF> From: <me@nowhere> To: <[email protected]> Hello, world. . 250 2.0.0 Ok: queued as C870D7CD93 QUIT 221 2.0.0 Bye 

Each row sent is a command, to which the distant server responds alongside a three numeral figure followed by a individual readable explaintaion. 200 responses average it worked, 300 is "carry on...", 400 indicates impermanent errors which inform the sender to try again later, 500 errors signify that the email have to be returned as un-deliverable.

(If this seems akin to HTTP, that's no coincidence. A lot of the web, including its header syntax, was lifted from SMTP)

The archetypal command is continually HELO (or EHLO), followed the sending MTA's hostname. This is normally not the identical hostname that's in an email address, but many providers necessitate it to equivalent the sender's IP address. . The next two, MAIL FROM and RCPT TO define the location to provision to, and the location for any nonaccomplishment notifications. Bounce messages are normally generated one stage up from anywhere the error occurred: in most cases the receiving MTA has a issue and sends an error code to the sending MTA, but by that period MSA has already disconnect, forcing an emailed notification. Those notification themselves use an bare MAIL FROM to evade infinite loops.

Once the location has been stated and accepted, a DATA command is sent, followed by the genuine message. This, at a minimum, contains the "From" and "To" headers alongside alongside several text. The communication is terminated alongside a solitary duration to which the server replies to signify that the communication was sucessfuly handed off.

Final hop MTAs should onward the email to the LDA before sending rear a position code. This ensures that they never obtain a communication which they can't deliver, which would outcome in a error notification. This "backscatter" communication interacts seriously alongside spammers that forge MAIL FROM: it turns their evidently bogus communication into one that is apt to be delivered and logic a nusance.

There is no necessity for the addresses inner the email to equivalent the ones in MAIL FROM and RCPT TO (also known as the envelope). The most average logic of this is a communication that has been forwarded. For example, a mailing catalog volition set the letter cover destination to equivalent all member's email, but keep the first "From" and "To" headers intact so that replies activity correctly. The letter cover from volition normally be changed to item to location the catalog director volition inspect for error notifications.

Now, it's not that intermediate systems don't modify the headers: Most stages volition add a "received" header to document anywhere they got the message.

While required for MTA to MTA communication, SMTP is used throughout the entire system. The communication client submits email using a distinct port, but complete the identical protocol. Communication between inner components (i.e. MTA to LDA) frequently uses the closely connected Local Mail Transfer Protocol: the chief difference is the assumption that the receiver doesn't have a communication queue and volition either provision the communication immediately or come back an error.

Submission normally uses TLS to harbor 465, alongside the supplement of a password (in base64):

 AUTH PLAIN 334 AGh1bnRlcgBodW50ZXIy 235 2.7.0 Authentication successful 

The one item that's considerably distinct is the MUA's fetch, which operates on a "pull" basis. I won't go into the syntax here, but it's not terribly complicated.

... but if you really try sending an email to, say, gmail, according to what I've written so far, it won't work. Some of that is because of them enforcing things akin the Message-Id header: a distinctive identifier used to de-duplicate communication in cases anywhere the receiving MTA accepts an email but the association drops before the sender is informed concerning this. This causes the sender to try again later, which duplicating the message.

However, a big part of it is...

Authentication

Base SMTP trusts that all sender is be fine behaved: anyone can dispatch email as anyone else. In fact, many hosts were configured to obtain and relay communication from anyone as a conveyance for whenever someone's customary server was down.

The first resolution to bad behavior was to get the culprit kicked off the internet... but that cut distinct quickly formerly the network grew and companies began getting involved: the archetypal documented case of spam email was sent in 1978 and sold 13 myriad dollars in computers. While authentication doesn't forestall spam, it makes it imaginable to display out unwanted senders.

Verifying sender addresses is not imaginable using the MX record, since there is no justify the identical presenter is used for receiving and sending mail. The simplest resolution is to publish the sending location in a seperate DNS record:

 @ TXT v=spf1 ip4:65.109.172.162 ip6:2a01:4f9:c011:841a:b01d::1 -all ; Roughly: ; authorize from 65.109.172.162 ; authorize from 2a01:4f9:c011:841a:b01d::1 ; refuse otherwise 

However, that's not fairly adequate for the email empire. Big-tech additionally wants the email build to be signed alongside a cryptographic key published via a (DKIM) DNS record. This requires adding a stage to sending mails, normally as a plugin for the MTA.

While I rag on big-tech a lot, but this is really a sensible policy: SPF can lone verify the MAIL FROM, since forwarding the email volition chance the origin IP address. DKIM signatures are attached to the communication and can be used to verify the first sender (the "From" address) of a message, which is what's really shown to the person in most cases.

However, the two of these don't really forestall spam, since spammers can fair set up a few TXT records. Big-tech additionally requires the sender's HELO hostname to be accordant alongside their IP address, via the two onward and reverse DNS. This helps forestall compromised devices from spewing out junk: a astute TV is improbable to have a meaningful PTR record, and if it does, that hostname won't determine rear to it's address.

... unfortunately this guideline additionally makes it unattainable to immediately dispatch communication from most residential net connections unless you own the location block. Of course, the resolution is to pay a big-tech business prosperity to relay your emails. If you don't akin this, discover a communication provider alongside additional permissive rules: the lone logic big-tech is capable to keep their racket operating that five or so companies authority 99% of email.

The message

This is anywhere SMTP stops being so simple. Let's appearance at the simplest imaginable email formerly it's been delivered:

 Return-Path: <alex@there> Delivered-To: bob@here Received: from here by current alongside LMTP id bs05E10S7Go4VQMAHrglgg (envelope-from <alex@there>) for <bob@here>; Thu, 05 Nov 2026 05:21:33 +0000 DKIM-Filter: OpenDKIM Filter v2.11.0 current B05E67CD18 Received-SPF: None (mailfrom) identity=mailfrom; client-ip=313.33.33.337; helo=there; envelope-from=alex@there; receiver=here Received: from there (unknown [313.33.333.337]) by current (Postfix) alongside SMTP id B05E67CD18 for <bob@here>; Thu, 05 Nov 2026 05:20:42 +0000 (UTC) From: alex@there To: bob@here Hello, World! 

The format of the headers is superficially akin to HTTP headers, except that no row should exceed 78 bytes. (without the CRLF row terminator) Overlong headers are damaged up and newly created lines are prefixed alongside whitespace to signify that they are a continuation of the final header.

Mail application mostly preppends headers to the commencement of a message, so it's helpful to peruse them backwards. "From" and "to" are fairly oneself explanatory. Next, the "received" header contains a note from the receiving MTA: it includes the source's HELO name, IP address, RCPT TO and a timestamp.

The MTA afterward performed SPF and DKIM checks, which came up empty: There's no signature and the MAIL FROM hostname is not publically resolvable.

The LDA added another "received" header, although it's not extremely helpful. More importantly, it tacked on the "return-path" alongside the first MAIL FROM location and recorded the mailbox the communication was delivered to.

However, the build isn't continually plain text. This is an email that includes formatting:

 [...] MIME-Version: 1.0 Content-Type: multipart/alternative; boundary=----IX71FHL6PHA0538LS1WKT2W9SF7S8X Content-Transfer-Encoding: 7bit ------IX71FHL6PHA0538LS1WKT2W9SF7S8X Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, World! I can do bold text! ------IX71FHL6PHA0538LS1WKT2W9SF7S8X Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable <!DOCTYPE html><html><body><div dir=3D"auto">Hello, world! I can do <b>bold&lt= /b> text</div></body></html> ------IX71FHL6PHA0538LS1WKT2W9SF7S8X-- 

That's right, it's a web page!

However, since not all email clients can comprehend HTML, the communication additionally includes a plain content version. This is done using MIME's "multipart" encoding, in this case, multipart/alternative, which indicates all the versions are functionally equivalent.

MIME's type figure has been stuck at 1.0 since 1996.

The delimiter is a randomly chosen string, which allows multiple multiparts to be nested inner without escaping. Each division of the communication has it's own headers, in this case, indicating that it's sent in the quoted-printable encoding. This allows the email communication to merge any bytes without exposing the MTA to scary things akin non-seven-bit ASCII: remember, the SMTP is 45 years old.

In quoted-printable, equal signs are used as the escape character: if followed by two hex digits, it decodes to that byte. If followed by a newline, the two characters are removed. This is used to interrupt lengthy lines that could alternatively logic trouble.

In this email, "=3D" becomes a literal equal sign and the two lines are joined together. If you've always seen an email alongside stray equals or missing one or two characters ~ all 80 bytes, damaged quoted-printable decoding is normally the culprit.

The second "content-transfer-encoding" is base64, which is used for binary records akin attached images:

 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="5ZTNvId/H+rlk7Fr" Content-Disposition: inline --5ZTNvId/H+rlk7Fr Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Check out this file: --5ZTNvId/H+rlk7Fr Content-Type: application/octet-stream Content-Disposition: attachment; filename="file.bin" Content-Transfer-Encoding: base64 J7mtSdbQItOAi345nwaNkkTXrnDIRPA0DSwhbSAOwm2C/KoHjQIotY9lnJRMBRk9InQaHOxL bb7DGd9EN6uRpjvCbox9xblAh3CxH7sl+YAkYcKw1V100RpBwMhgaXfUJBB3oRkLffgRwEyK v9qFBLp9zZ+SiRJoRWbA4aZLexPhHZ35vFROVKYtiAeMlD1s15v3kPZvEADam0e45BoSaqmp 1S3z3b5wBIFHJUxQULD589MKaFx2Z2A+91pl/pbZWmZkzt55D/hZ05kjUUbXUnDnTYAQE2Gk WnN+SnrQvfEO+Tz7AdrbLD1q2DgwWW+k0cVJLKjdwRxesGhAkQCZfHVrno6R4iXjTbInIbQv hXzQiV840iUiUhk282WADd1ffJ0sot2Waf7XHLIE1lZVFQ3iGofYbw8pZlg3sb35AnIWPZKv fbC6Yh95RV23R4K2NHeBX1rpl4bSSiftnD2RbsBzv7cgw/6M/Lj3O40NFGAaUC+J7TpAaXdi tvlPsNQhMo8QRf/ub7WK42cPUlz1fKq1k1pzGN96YOsE5azMfF4vLANtbtbVmLIp2WmgBk0P 9IGMWy/xIAe0cOh+bqzru2+ojJGgx9uX4VSTP9BaTOwkVX5+rQfpp1qJodtHiO8sHw6Pg+Mg WcpqQPC7118ccuT44cVpIRkwOSoJzsW++WM= --5ZTNvId/H+rlk7Fr-- 

This is why size limits are frequently disappointing: the email volition be 33% larger than the attached file. More productive encodings (raw binary data) are supported by several MTAs, but may have to be converted to base64 location downward the path... which would interrupt DKIM signing.

Generally:

  • No encoding ("7-bit") can be used if the communication has abbreviated lines and fits in low-bit ASCII. However, "7-bit" is mostly seen as a null encoding for already encoded multipart containers.
  • Quoted-printable if the communication is mostly text, but has item that risks breaking ancient software.
  • Base64 for binary data.

About TLS

The SSL/TLS used by communication clients is efficiently the identical as for a browser: the communication provider must go to a certificate authority, demonstrate their character and get a certificate.. Algorithms and ciphers are impaired at the least clue they may be insecure.

However, MTAs operates on "trusted" networks... although it's small that an attacker can't get admission to net traffic, but that if they could, it would be imaginable for them to continue an ACME difficulty and obtain out a trusted certificate.

As a result, the goal is mostly to defend against passive eavesdropping: most sysadmins don't annoy dealing alongside a CA and use self-signed certificates. (it's not akin CAs have a fine track record: 4)

Another weird item concerning email is that MTAs don't use a distinct TLS port. All connections on harbor 25 commencement as plaintext, afterward the sender issues a STARTTLS command and hands complete the association to a SSL/TLS library. It's slightly janky, but it allows servers to attempt to use encryption and cleanly autumn rear if it's not supported.

Such an method isn't awesome for submissions, since a autumn rear would leak the password... and baddies on shared networks or nosy residential ISPs can band out the STARTTLS command. For this case, it's finest to default use the dedicated SSL submission port: 465.

(This harbor really has a bit of a history, alongside it being deprecated in favor of STARTTLS before being re-endorsed formerly we realized using optional SSL for passwords was a bad idea.)

So what??

Unless you compose email connected application or run infrastructure, most of this data is deeply useless. However, there are a few things you power desire to remember.

The underlying protocols authorize five days for delivery, and it can sometimes obtain longer. Since users anticipate shipment in seconds and most emails are at smallest slightly period sensitive, some MTAs are configured to dispatch out postpone notification if a communication is taking a while.

You may desire to discover out if yours does this before assuming the recipient is ignoring you.

Emails are digital postcards.

A communication volition be stored and forwarded by multiple systems in plaintext. Anyone on the network way may be capable to peruse your email: SSL/TLS is not universally supported and can trivially be stripped out by energetic attackers.

This is an inherent part of email: there's no way to tack-on powerful encryption without breaking existing clients. If you need a justify of privacy, you must encrypt the communication before sending, and the recipient must decrypt it themselves. Be careful alongside built-in tools akin PGP: these mostly create it way too uncomplicated to accidentally hit "reply-all" without encrypting, in supplement to another flaws akin exposing the topic line.

PGP stuff

Since publication, multiple group have written to me explaining how obfuscating the topic row (or alert if the person fills it out) is completly unreasonable to anticipate from a for a self-proclaimed privacy tool. At smallest in my eyes, "encrypted messaging" method encrypted, not 90% encrypted and 10% plaintext.

The deficiency of deniablity and onward secrecy can be excused as limitiations of email's store-and-forward architecture... but default plaintext and making no attempt to encrypt certain the topic row or attachments is a formula for disaster: at smallest alongside vanilla email, group cognize it is not encrypted.

"Encrypted" email providers are mostly snake oil. While the communication shop can encrypt messages and a tradition MUA could decrypt them, the MTA must have admission to plaintext. As a result, it provides minimal to no safety against most assault vectors notwithstanding the "millitary class encryption". The lone way to fix email would be to get everyone to concur to toggle to an end-to-end encrypted protocol... but the entire item of email is worldwide compatability: encrypted messaging can exist, but encrypted email is contradictory.

The finest anticipation is to discover a communication provider that can be trusted not to snoop messages. That is to say, not an Advertising business (google) or one that's been pushing difficult for LLMs (microsoft / apple): both of these businesses create powerful incentives to peruse your messages. Although you'll motionless have to anticipation whoever you are communicating alongside isn't beign snooped on by their provider.

Worse, DKIM signatures act as a lifelong evidence that an email came from your provider's servers, equal if a communication is years old and has no apparent sequence of custody. This makes leaked, hacked, or snooped emails ideal blackmail material: since the bad performer can trivially demonstrate they haven't been fabricated.

This property, called non-repudiation, is mostly not desirable for messaging systems. Avoiding signing not an choice if you desire to interoperate alongside big-tech, but it is imaginable to regularly rotate and publish personal keys. Before they key is published, the signature can be trusted to verify it is legitimate. However, formerly the key has been published, the signature can been forged by anyone and is rendered retroactively untrustworthy.

Since authentication is checked during shipment by the MTA and LDA, this doesn't power how the email volition be handled. However, it volition mold doubt on the authenticity of leaked messages since the signature could have been forged alongside minimal effort.

While key rotation is average practice, most communication providers don't publish their old personal keys, so the signature is motionless trustworthy (modulo the assistance being hacked). I would advise against emailing item you wouldn't be comfortable study out in public.

Other Article Hacker News
↑
Close Right Ads
Close Left Ads