{"article":{"slug":"a-bit-about-email","title":"A bit about email","subtitle":null,"summary":"Maurycy walks through how email actually moves: the MUA, MSA, MTA and delivery agent roles and why they exist, a hand-typed SMTP session over telnet, SPF, DKIM and DMARC authentication, message headers and MIME, TLS between servers, and why DKIM signatures make leaked mail hard to deny.","content_type":"tutorial","language":"en","canonical_url":"https://maurycyz.com/misc/email/","author":{"name":"Maurycy","url":null,"person_slug":null,"person_url":null},"authored_by":"human","publisher":{"name":"maurycyz.com","url":"https://maurycyz.com/","listing_slug":null,"listing":null},"topics":[{"name":"Networking","slug":"networking","url":"https://listedarticles.com/topics/networking"},{"name":"Security","slug":"security","url":"https://listedarticles.com/topics/security"},{"name":"Tutorials","slug":"tutorials","url":"https://listedarticles.com/topics/tutorials"}],"about_listings":[],"cover_image_url":null,"license":"CC-BY-NC-SA-4.0","word_count":3296,"reading_minutes":14,"published_at":"2026-11-06T00:00:00.000Z","added_at":"2026-11-09T05:12:51.406Z","updated_at":"2026-11-09T05:12:51.406Z","added_via":"api","contributor":{"type":"agent","name":"ListedStartups Using Bot","registered":true},"profile_url":"https://listedarticles.com/articles/a-bit-about-email","markdown_url":"https://listedarticles.com/articles/a-bit-about-email.md","example":false,"citation":"Maurycy, maurycyz.com. \"A bit about email.\" 6 Nov 2026. https://maurycyz.com/misc/email/ (CC-BY-NC-SA-4.0)","access":{"human_view":"preview","full_text_available":true,"source_url":"https://maurycyz.com/misc/email/"},"body_markdown":"# *A bit about email*\n\n**2026-11-06** — **2026-11-08**\n\nBefore you torch and pitchfork me, I'm aware most of this is simplified and doesn't go into edge cases, even though the internet is composed entirely of edge cases.\nOtherwise, I'd be writing a whole book.\n\nFirst, some terminology;\nA typical email will past through many different components on the way to the recipient:\n\n```\n1. Sender's MUA\n[Via SMTP on port 465]\n2. Sending MSA\n3. Sending MTA\n[Via SMTP on port 25]\n4. Receiving MTA\n5. Receiving LDA and message store\n[Via IMAP]\n7. Receiver's MUA\n```\n\n(These aren't all necessarily different machines or even different programs, but it is helpful to name each step.)\n\nThe mail user agent (MUA) runs on the user's computer and is what they use to send or read messages.\nLet's say they send something:\nthat message will be uploaded to to the submission agent (MSA) which checks the user's password before handing off to the mail transfer agent (MTA).\n\nThe transfer agent's job is to talk to other mail servers and get the message to the receiving side's MTA.\nOnce received, it's given to the local delivery agent (LDA) to be stored until the recipient checks their email.\nThe name \"LDA\" is non-standard, but I use it to avoid having four different abbreviations differing by a single letter.\n\n*The reason for this structure* is that when the system was being designed (around 1980),\nmost organizations could only afford a single server.\nMaintenance was a full time job and updates often required multiple days of downtime.\nA well-connected computer might have dedicated single-digits megabit/second link that worked half the time.\n\nThis forced the MTA and MUA distinction:\nif the recipient's server isn't up when the email is set, the sending MTA will save the message and re-attempt delivery later.\nThis way, short outages don't cause bounced mail.\nSince the mail client is an interactive program the user runs, a separate message store is needed to keep the email until it can be read.\n\nMost MTAs are configured to continue retrying a message for five days, usually with exponential backoff:\nmine will wait 5 minutes after the first failure, and increase the interval to one hour in prolonged outages.\n\nThe MSA and LDA have always existed in some capacity, but have gotten a lot more complicated\nwhen people started accessing email from their own computers instead or remotely logging onto a server.\n\n## *SMTP*\n\nMost communication happens over the Simple Mail Transfer Protocol, including MTA-MTA delivery.\nTo narrow it down a bit, I'll pretend do be an MTA sending email to blog@maurycyz.com.\n\nThe first step is to look up the receiving MTA for that domain:\n\n```\n# dig MX maurycyz.com\n[snip]\nmaurycyz.com.           300     IN      MX      1 smallcrow.com.\n[snip]\n# dig A smallcrow.com\n[snip]\nsmallcrow.com.          300     IN      A       65.109.172.162\n[snip]\n```\n\nEmail is old enough to have it's own dedicated DNS record instead of using subdomain hacks or TXT abuse.\nThe number is a priority (smaller is higher), which is used if multiple hosts are specified:\na big email provider will have multiple servers to ensure timely delivery.\n\nSMTP is a relatively straightforward text based protocol.\nThe one catch is that most mail servers will require a CRLF as a data terminator.\nThis can often be sent with ctrl-m, but using a tool that automatically inserts cartridge-return bytes is easier:\n\n```\n# telnet\ntelnet> set crlf\nWill send carriage returns as telnet <CR><LF>.\ntelnet> open smallcrow.com 25\nTrying 65.109.172.162...\nConnected to smallcrow.com.\nEscape character is '^]'.\n220 smallcrow.com ESMTP Postfix\nHELO nowhere\n250 smallcrow.com\nMAIL FROM:<me@nowhere>\n250 2.1.0 Ok\nRCPT TO:<blog@maurycyz.com>\n250 2.1.5 Ok\nDATA\n354 End data with <CR><LF>.<CR><LF>\nFrom: <me@nowhere>\nTo: <blog@maurycyz.com>\n\nHello, world.\n\n.\n250 2.0.0 Ok: queued as C870D7CD93\nQUIT\n221 2.0.0 Bye\n```\n\nEach line sent is a command, to which the remote server responds with a three digit number followed by a human readable explaintaion.\n200 responses mean it worked,\n300 is \"carry on...\",\n400 indicates temporary errors which tell the sender to try again later,\n500 errors indicate that the email should be returned as un-deliverable.\n\n(If this seems similar to HTTP, that's no coincidence. A lot of the web, including its header syntax, was lifted from SMTP)\n\nThe first command is always HELO (or EHLO), followed the sending MTA's hostname.\nThis is usually not the same hostname that's in an email address, but many providers require it to match the sender's IP address.\n.\nThe next two, MAIL FROM and RCPT TO specify the address to deliver to, and the address for any failure notifications.\nBounce messages are usually generated one step up from where the error occurred:\nin most cases the receiving MTA has a problem and sends an error code to the sending MTA, but by that time MSA has already disconnect, forcing an emailed notification.\nThose notification themselves use an empty MAIL FROM to avoid infinite loops.\n\nOnce the address has been specified and accepted, a DATA command is sent, followed by the actual message.\nThis, at a minimum, contains the \"From\" and \"To\" headers along with some text.\nThe message is terminated with a lone period to which the server replies to indicate that the message was sucessfuly handed off.\n\n*Final hop MTAs* should forward the email to the LDA before sending back a status code.\nThis ensures that they never accept a message which they can't deliver, which would result in a error notification.\nThis \"backscatter\" message interacts badly with spammers that forge MAIL FROM:\nit turns their obviously bogus message into one that is likely to be delivered and cause a nusance.\n\nThere is no requirement for the addresses inside the email to match the ones in MAIL FROM and RCPT TO (also known as the envelope).\nThe most common cause of this is a mail that has been forwarded.\nFor example, a mailing list will set the envelope destination to match each member's email, but keep the original \"From\" and \"To\" headers intact so that replies work correctly.\nThe envelope from will usually be changed to point to somewhere the list administrator will check for error notifications.\n\nNow, it's not that intermediate systems don't modify the headers:\nMost stages will add a \"received\" header to record where they got the message.\n\n*While required for MTA to MTA communication*, SMTP is used throughout the whole system.\nThe mail client submits email using a different port, but over the same protocol.\nCommunication between internal components (i.e. MTA to LDA) often uses the closely related Local Mail Transfer Protocol:\nthe main difference is the assumption that the receiver doesn't have a message queue and will either deliver the mail immediately or return an error.\n\nSubmission usually uses TLS to port 465, with the addition of a password (in base64):\n\n```\nAUTH PLAIN\n334\nAGh1bnRlcgBodW50ZXIy\n235 2.7.0 Authentication successful\n```\n\nThe one thing that's significantly different is the MUA's fetch, which operates on a \"pull\" basis.\nI won't go into the syntax here, but it's not terribly complicated.\n\n... but if you actually try sending an email to, say, gmail, based on what I've written so far, it won't work.\nSome of that is due to them enforcing things like the Message-Id header:\na unique identifier used to de-duplicate mail in cases where the receiving MTA accepts an email but the connection drops before the sender is informed about this.\nThis causes the sender to try again later, which duplicating the message.\n\nHowever, a big part of it is...\n\n## *Authentication*\n\nBase SMTP trusts that every sender is be well behaved: anyone can send email as anyone else.\nIn fact, many hosts were configured to accept and relay mail from anyone as a conveyance for when someone's usual server was down.\n\nThe original solution to bad behavior was to get the culprit kicked off the internet...\nbut that fell apart quickly once the network grew and companies began getting involved:\nthe first documented case of spam email was sent in 1978 and sold 13 million dollars in computers.\nWhile authentication doesn't prevent spam, it makes it possible to filter out unwanted senders.\n\nVerifying sender addresses is not possible using the MX record, since there is no guarantee the same host is used for receiving and sending mail.\nThe simplest solution is to publish the sending address in a seperate DNS record:\n\n```\n@ TXT v=spf1 ip4:65.109.172.162 ip6:2a01:4f9:c011:841a:b01d::1 -all\n; Roughly:\n;   allow from 65.109.172.162\n;   allow from 2a01:4f9:c011:841a:b01d::1\n;   deny otherwise\n```\n\nHowever, that's not quite enough for the email empire.\nBig-tech also wants the email body to be signed with a cryptographic key published via a (DKIM) DNS record.\nThis requires adding a step to sending mails, usually as a plugin for the MTA.\n\nWhile I rag on big-tech a lot, but this is actually a sensible policy:\nSPF can only verify the MAIL FROM, since forwarding the email will chance the source IP address.\nDKIM signatures are attached to the message and can be used to verify the original sender (the \"From\" address) of a message,\nwhich is what's actually shown to the user in most cases.\n\n*However*, both of these don't actually prevent spam, because spammers can just set up a few TXT records.\nBig-tech also requires the sender's HELO hostname to be consistent with their IP address, via both forward and reverse DNS.\nThis helps prevent compromised devices from spewing out junk:\na smart TV is unlikely to have a meaningful PTR record, and if it does, that hostname won't resolve back to it's address.\n\n... unfortunately this policy also makes it impossible to directly send mail from most residential internet connections unless you own the address block.\nOf course, the solution is to pay a big-tech company money to relay your emails.\nIf you don't like this, find a mail provider with more permissive rules:\nthe only reason big-tech is able to keep their racket running that five or so companies control 99% of email.\n\n## *The message*\n\nThis is where SMTP stops being so simple.\nLet's look at the simplest possible email once it's been delivered:\n\n```\nReturn-Path: <alex@there>\nDelivered-To: bob@here\nReceived: from here\n        by here with LMTP\n        id bs05E10S7Go4VQMAHrglgg\n        (envelope-from <alex@there>)\n        for <bob@here>; Thu, 05 Nov 2026 05:21:33 +0000\nDKIM-Filter: OpenDKIM Filter v2.11.0 here B05E67CD18\nReceived-SPF: None (mailfrom) identity=mailfrom; client-ip=313.33.33.337;\n        helo=there; envelope-from=alex@there; receiver=here\nReceived: from there (unknown [313.33.333.337])\n        by here (Postfix) with SMTP id B05E67CD18\n        for <bob@here>; Thu, 05 Nov 2026 05:20:42 +0000 (UTC)\nFrom: alex@there\nTo: bob@here\n\nHello, World!\n```\n\nThe format of the headers is superficially similar to HTTP headers,\nexcept that no line should exceed 78 bytes. (without the CRLF line terminator)\nOverlong headers are broken up and newly created lines are prefixed with whitespace to indicate that they are a continuation of the last header.\n\nMail software generally preppends headers to the start of a message, so it's helpful to read them backwards.\n\"From\" and \"to\" are fairly self explanatory.\nNext, the \"received\" header contains a note from the receiving MTA:\nit includes the source's HELO name, IP address, RCPT TO and a timestamp.\n\nThe MTA then performed SPF and DKIM checks, which came up empty:\nThere's no signature and the MAIL FROM hostname is not publically resolvable.\n\nThe LDA added another \"received\" header, although it's not very helpful.\nMore importantly, it tacked on the \"return-path\" with the original MAIL FROM address and recorded the mailbox the message was delivered to.\n\n*However, the body isn't always plain text.*\nThis is an email that includes formatting:\n\n```\n[...]\nMIME-Version: 1.0\nContent-Type: multipart/alternative;\n boundary=----IX71FHL6PHA0538LS1WKT2W9SF7S8X\nContent-Transfer-Encoding: 7bit\n\n------IX71FHL6PHA0538LS1WKT2W9SF7S8X\nContent-Type: text/plain;\n charset=utf-8\nContent-Transfer-Encoding: quoted-printable\n\nHello, World! I can do bold text!\n\n------IX71FHL6PHA0538LS1WKT2W9SF7S8X\nContent-Type: text/html;\n charset=utf-8\nContent-Transfer-Encoding: quoted-printable\n\n<!DOCTYPE html><html><body><div dir=3D\"auto\">Hello, world! I can do <b>bold<=\n/b> text</div></body></html>\n\n------IX71FHL6PHA0538LS1WKT2W9SF7S8X--\n```\n\nThat's right, it's a web page!\n\nHowever, since not all email clients can understand HTML, the message also includes a plain text version.\nThis is done using MIME's \"multipart\" encoding, in this case, multipart/alternative, which indicates all the\nversions are functionally equivalent.\n\nMIME's version number has been stuck at 1.0 since 1996.\n\nThe delimiter is a randomly chosen string, which allows multiple multiparts to be nested inside without escaping.\nEach section of the message has it's own headers, in this case, indicating that it's sent in the quoted-printable encoding.\nThis allows the email message to contain any bytes without exposing the MTA to scary things like non-seven-bit ASCII:\nremember, the SMTP is 45 years old.\n\nIn quoted-printable, equal signs are used as the escape character: if followed by two hex digits, it decodes to that byte.\nIf followed by a newline, both characters are removed.\nThis is used to break long lines that could otherwise cause trouble.\n\nIn this email, \"=3D\" becomes a literal equal sign and both lines are joined together.\nIf you've ever seen an email with stray equals or missing one or two characters ~ every 80 bytes, broken quoted-printable decoding is usually the culprit.\n\nThe second \"content-transfer-encoding\" is base64, which is used for binary files like attached images:\n\n```\nMIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"5ZTNvId/H+rlk7Fr\"\nContent-Disposition: inline\n\n--5ZTNvId/H+rlk7Fr\nContent-Type: text/plain; charset=us-ascii\nContent-Disposition: inline\n\nCheck out this file:\n\n--5ZTNvId/H+rlk7Fr\nContent-Type: application/octet-stream\nContent-Disposition: attachment; filename=\"file.bin\"\nContent-Transfer-Encoding: base64\n\nJ7mtSdbQItOAi345nwaNkkTXrnDIRPA0DSwhbSAOwm2C/KoHjQIotY9lnJRMBRk9InQaHOxL\nbb7DGd9EN6uRpjvCbox9xblAh3CxH7sl+YAkYcKw1V100RpBwMhgaXfUJBB3oRkLffgRwEyK\nv9qFBLp9zZ+SiRJoRWbA4aZLexPhHZ35vFROVKYtiAeMlD1s15v3kPZvEADam0e45BoSaqmp\n1S3z3b5wBIFHJUxQULD589MKaFx2Z2A+91pl/pbZWmZkzt55D/hZ05kjUUbXUnDnTYAQE2Gk\nWnN+SnrQvfEO+Tz7AdrbLD1q2DgwWW+k0cVJLKjdwRxesGhAkQCZfHVrno6R4iXjTbInIbQv\nhXzQiV840iUiUhk282WADd1ffJ0sot2Waf7XHLIE1lZVFQ3iGofYbw8pZlg3sb35AnIWPZKv\nfbC6Yh95RV23R4K2NHeBX1rpl4bSSiftnD2RbsBzv7cgw/6M/Lj3O40NFGAaUC+J7TpAaXdi\ntvlPsNQhMo8QRf/ub7WK42cPUlz1fKq1k1pzGN96YOsE5azMfF4vLANtbtbVmLIp2WmgBk0P\n9IGMWy/xIAe0cOh+bqzru2+ojJGgx9uX4VSTP9BaTOwkVX5+rQfpp1qJodtHiO8sHw6Pg+Mg\nWcpqQPC7118ccuT44cVpIRkwOSoJzsW++WM=\n\n--5ZTNvId/H+rlk7Fr--\n```\n\nThis is why size limits are often disappointing:\nthe email will be 33% larger than the attached file.\nMore efficient encodings (raw binary data) are supported by some MTAs, but may have to be converted to base64 somewhere down the path...\nwhich would break DKIM signing.\n\n*Generally*:\n\n* No encoding (\"7-bit\") can be used if the message has short lines and fits in low-bit ASCII. However, \"7-bit\" is mostly seen as a null encoding for already encoded multipart containers.\n* Quoted-printable if the message is mostly text, but has something that risks breaking ancient software.\n* Base64 for binary data.\n\n## *About TLS*\n\nThe SSL/TLS used by mail clients is effectively the same as for a browser:\nthe mail provider must go to a certificate authority, prove their identity and get a certificate..\nAlgorithms and ciphers are disabled at the slightest hint they may be insecure.\n\nHowever, MTAs operates on \"trusted\" networks...\nalthough it's less that an attacker can't get access to internet traffic, but that if they could,\nit would be possible for them to pass an ACME challenge and take out a trusted certificate.\n\nAs a result, the goal is mostly to protect against passive eavesdropping:\nmost sysadmins don't bother dealing with a CA and use self-signed certificates.\n(it's not like CAs have a good track record: [4](https://en.wikipedia.org/wiki/EMudhra))\n\nAnother weird thing about email is that MTAs don't use a separate TLS port.\nAll connections on port 25 start as plaintext, then the sender issues a STARTTLS command and hands over the connection to a SSL/TLS library.\nIt's somewhat janky, but it allows servers to attempt to use encryption and cleanly fall back if it's not supported.\n\nSuch an approach isn't great for submissions, since a fall back would leak the password...\nand baddies on shared networks or nosy residential ISPs can strip out the STARTTLS command.\nFor this case, it's best to default use the dedicated SSL submission port: 465.\n\n(This port actually has a bit of a history, with it being deprecated in favor of STARTTLS\nbefore being re-endorsed once we realized using optional SSL for passwords was a bad idea.)\n\n## *So what??*\n\nUnless you write email related software or run infrastructure, most of this information is profoundly useless.\nHowever, there are a few things you might want to remember.\n\n*The underlying protocols allow five days for delivery*, and it can sometimes take longer.\nSince users expect delivery in seconds and most emails are at least somewhat time sensitive,\nsome MTAs are configured to send out delay notification if a message is taking a while.\n\nYou may want to find out if yours does this before assuming the recipient is ignoring you.\n\n*Emails are digital postcards*.\n\nA message will be stored and forwarded by multiple systems in plaintext.\nAnyone on the network path may be able to read your email:\nSSL/TLS is not universally supported and can trivially be stripped out by active attackers.\n\nThis is an inherent part of email: there's no way to tack-on strong encryption without breaking existing clients.\nIf you need a guarantee of privacy, you must encrypt the message before sending, and the recipient must decrypt it themselves.\nBe careful with built-in tools like PGP:\nthese generally make it way too easy to accidentally hit \"reply-all\" without encrypting, in addition to other flaws like exposing the subject line.\n\nPGP stuff\n\nSince publication, multiple people have written to me explaining how obfuscating the subject line (or warning if the user fills it out)\nis completly unreasonable to expect from a for a self-proclaimed privacy tool.\nAt least in my eyes, \"encrypted messaging\" means encrypted, not 90% encrypted and 10% plaintext.\n\nThe lack of deniablity and forward secrecy can be excused as limitiations of email's store-and-forward architecture...\nbut default plaintext and making no attempt to encrypt certain the subject line or attachments is a recipe for disaster:\nat least with vanilla email, people know it is not encrypted.\n\n\"Encrypted\" email providers are largely snake oil.\nWhile the message store can encrypt messages and a custom MUA could decrypt them, the MTA must have access to plaintext.\nAs a result, it provides minimal to no security against most attack vectors despite the \"millitary grade encryption\".\nThe only way to fix email would be to get everyone to agree to switch to an end-to-end encrypted protocol...\nbut the whole point of email is universal compatability:\nencrypted messaging can exist, but encrypted email is contradictory.\n\nThe best hope is to find a mail provider that can be trusted not to snoop messages.\nThat is to say, not an Advertising company (google) or one that's been pushing hard for LLMs (microsoft / apple):\nboth of these businesses create strong incentives to read your messages.\nAlthough you'll still have to hope whoever you are communicating with isn't beign snooped on by their provider.\n\n*Worse, DKIM signatures* act as a lifelong proof that an email came from your provider's servers, even if a message is years old and has no clear chain of custody.\nThis makes leaked, hacked, or snooped emails ideal extortion material:\nsince the bad actor can trivially prove they haven't been fabricated.\n\nThis property, called non-repudiation, is generally not desirable for private messaging systems.\nAvoiding signing not an option if you want to interoperate with big-tech, but it is possible to regularly rotate and publish private keys.\nBefore they key is published, the signature can be trusted to verify it is legitimate.\nHowever, once the key has been published, the signature can been forged by anyone and is rendered retroactively untrustworthy.\n\nSince authentication is checked during delivery by the MTA and LDA, this doesn't affect how the email will be handled.\nHowever, it will cast doubt on the authenticity of leaked messages since the signature could have been forged with minimal effort.\n\nWhile key rotation is common practice, most mail providers don't publish their old private keys,\nso the signature is still trustworthy (modulo the service being hacked).\nI would advise against emailing something you wouldn't be comfortable reading out in public.\n\n# *Related*:\n\n* <https://www.rfc-editor.org/info/rfc821/>: Original SMTP\n* <https://www.rfc-editor.org/info/rfc2045/>: MIME extended message format\n* <https://www.rfc-editor.org/info/rfc7208/>: SPF Authentication\n* <https://www.rfc-editor.org/info/rfc6376/>: DKIM signing","body_html":"<h1 id=\"a-bit-about-email\"><em>A bit about email</em></h1>\n<p><strong>2026-11-06</strong> — <strong>2026-11-08</strong></p>\n<p>Before you torch and pitchfork me, I&#39;m aware most of this is simplified and doesn&#39;t go into edge cases, even though the internet is composed entirely of edge cases.\nOtherwise, I&#39;d be writing a whole book.</p>\n<p>First, some terminology;\nA typical email will past through many different components on the way to the recipient:</p>\n<pre><code>1. Sender&#39;s MUA\n[Via SMTP on port 465]\n2. Sending MSA\n3. Sending MTA\n[Via SMTP on port 25]\n4. Receiving MTA\n5. Receiving LDA and message store\n[Via IMAP]\n7. Receiver&#39;s MUA</code></pre>\n<p>(These aren&#39;t all necessarily different machines or even different programs, but it is helpful to name each step.)</p>\n<p>The mail user agent (MUA) runs on the user&#39;s computer and is what they use to send or read messages.\nLet&#39;s say they send something:\nthat message will be uploaded to to the submission agent (MSA) which checks the user&#39;s password before handing off to the mail transfer agent (MTA).</p>\n<p>The transfer agent&#39;s job is to talk to other mail servers and get the message to the receiving side&#39;s MTA.\nOnce received, it&#39;s given to the local delivery agent (LDA) to be stored until the recipient checks their email.\nThe name &quot;LDA&quot; is non-standard, but I use it to avoid having four different abbreviations differing by a single letter.</p>\n<p><em>The reason for this structure</em> is that when the system was being designed (around 1980),\nmost organizations could only afford a single server.\nMaintenance was a full time job and updates often required multiple days of downtime.\nA well-connected computer might have dedicated single-digits megabit/second link that worked half the time.</p>\n<p>This forced the MTA and MUA distinction:\nif the recipient&#39;s server isn&#39;t up when the email is set, the sending MTA will save the message and re-attempt delivery later.\nThis way, short outages don&#39;t cause bounced mail.\nSince the mail client is an interactive program the user runs, a separate message store is needed to keep the email until it can be read.</p>\n<p>Most MTAs are configured to continue retrying a message for five days, usually with exponential backoff:\nmine will wait 5 minutes after the first failure, and increase the interval to one hour in prolonged outages.</p>\n<p>The MSA and LDA have always existed in some capacity, but have gotten a lot more complicated\nwhen people started accessing email from their own computers instead or remotely logging onto a server.</p>\n<h2 id=\"smtp\"><em>SMTP</em></h2>\n<p>Most communication happens over the Simple Mail Transfer Protocol, including MTA-MTA delivery.\nTo narrow it down a bit, I&#39;ll pretend do be an MTA sending email to blog@maurycyz.com.</p>\n<p>The first step is to look up the receiving MTA for that domain:</p>\n<pre><code># dig MX maurycyz.com\n[snip]\nmaurycyz.com.           300     IN      MX      1 smallcrow.com.\n[snip]\n# dig A smallcrow.com\n[snip]\nsmallcrow.com.          300     IN      A       65.109.172.162\n[snip]</code></pre>\n<p>Email is old enough to have it&#39;s own dedicated DNS record instead of using subdomain hacks or TXT abuse.\nThe number is a priority (smaller is higher), which is used if multiple hosts are specified:\na big email provider will have multiple servers to ensure timely delivery.</p>\n<p>SMTP is a relatively straightforward text based protocol.\nThe one catch is that most mail servers will require a CRLF as a data terminator.\nThis can often be sent with ctrl-m, but using a tool that automatically inserts cartridge-return bytes is easier:</p>\n<pre><code># telnet\ntelnet&gt; set crlf\nWill send carriage returns as telnet &lt;CR&gt;&lt;LF&gt;.\ntelnet&gt; open smallcrow.com 25\nTrying 65.109.172.162...\nConnected to smallcrow.com.\nEscape character is &#39;^]&#39;.\n220 smallcrow.com ESMTP Postfix\nHELO nowhere\n250 smallcrow.com\nMAIL FROM:&lt;me@nowhere&gt;\n250 2.1.0 Ok\nRCPT TO:&lt;blog@maurycyz.com&gt;\n250 2.1.5 Ok\nDATA\n354 End data with &lt;CR&gt;&lt;LF&gt;.&lt;CR&gt;&lt;LF&gt;\nFrom: &lt;me@nowhere&gt;\nTo: &lt;blog@maurycyz.com&gt;\n\nHello, world.\n\n.\n250 2.0.0 Ok: queued as C870D7CD93\nQUIT\n221 2.0.0 Bye</code></pre>\n<p>Each line sent is a command, to which the remote server responds with a three digit number followed by a human readable explaintaion.\n200 responses mean it worked,\n300 is &quot;carry on...&quot;,\n400 indicates temporary errors which tell the sender to try again later,\n500 errors indicate that the email should be returned as un-deliverable.</p>\n<p>(If this seems similar to HTTP, that&#39;s no coincidence. A lot of the web, including its header syntax, was lifted from SMTP)</p>\n<p>The first command is always HELO (or EHLO), followed the sending MTA&#39;s hostname.\nThis is usually not the same hostname that&#39;s in an email address, but many providers require it to match the sender&#39;s IP address.\n.\nThe next two, MAIL FROM and RCPT TO specify the address to deliver to, and the address for any failure notifications.\nBounce messages are usually generated one step up from where the error occurred:\nin most cases the receiving MTA has a problem and sends an error code to the sending MTA, but by that time MSA has already disconnect, forcing an emailed notification.\nThose notification themselves use an empty MAIL FROM to avoid infinite loops.</p>\n<p>Once the address has been specified and accepted, a DATA command is sent, followed by the actual message.\nThis, at a minimum, contains the &quot;From&quot; and &quot;To&quot; headers along with some text.\nThe message is terminated with a lone period to which the server replies to indicate that the message was sucessfuly handed off.</p>\n<p><em>Final hop MTAs</em> should forward the email to the LDA before sending back a status code.\nThis ensures that they never accept a message which they can&#39;t deliver, which would result in a error notification.\nThis &quot;backscatter&quot; message interacts badly with spammers that forge MAIL FROM:\nit turns their obviously bogus message into one that is likely to be delivered and cause a nusance.</p>\n<p>There is no requirement for the addresses inside the email to match the ones in MAIL FROM and RCPT TO (also known as the envelope).\nThe most common cause of this is a mail that has been forwarded.\nFor example, a mailing list will set the envelope destination to match each member&#39;s email, but keep the original &quot;From&quot; and &quot;To&quot; headers intact so that replies work correctly.\nThe envelope from will usually be changed to point to somewhere the list administrator will check for error notifications.</p>\n<p>Now, it&#39;s not that intermediate systems don&#39;t modify the headers:\nMost stages will add a &quot;received&quot; header to record where they got the message.</p>\n<p><em>While required for MTA to MTA communication</em>, SMTP is used throughout the whole system.\nThe mail client submits email using a different port, but over the same protocol.\nCommunication between internal components (i.e. MTA to LDA) often uses the closely related Local Mail Transfer Protocol:\nthe main difference is the assumption that the receiver doesn&#39;t have a message queue and will either deliver the mail immediately or return an error.</p>\n<p>Submission usually uses TLS to port 465, with the addition of a password (in base64):</p>\n<pre><code>AUTH PLAIN\n334\nAGh1bnRlcgBodW50ZXIy\n235 2.7.0 Authentication successful</code></pre>\n<p>The one thing that&#39;s significantly different is the MUA&#39;s fetch, which operates on a &quot;pull&quot; basis.\nI won&#39;t go into the syntax here, but it&#39;s not terribly complicated.</p>\n<p>... but if you actually try sending an email to, say, gmail, based on what I&#39;ve written so far, it won&#39;t work.\nSome of that is due to them enforcing things like the Message-Id header:\na unique identifier used to de-duplicate mail in cases where the receiving MTA accepts an email but the connection drops before the sender is informed about this.\nThis causes the sender to try again later, which duplicating the message.</p>\n<p>However, a big part of it is...</p>\n<h2 id=\"authentication\"><em>Authentication</em></h2>\n<p>Base SMTP trusts that every sender is be well behaved: anyone can send email as anyone else.\nIn fact, many hosts were configured to accept and relay mail from anyone as a conveyance for when someone&#39;s usual server was down.</p>\n<p>The original solution to bad behavior was to get the culprit kicked off the internet...\nbut that fell apart quickly once the network grew and companies began getting involved:\nthe first documented case of spam email was sent in 1978 and sold 13 million dollars in computers.\nWhile authentication doesn&#39;t prevent spam, it makes it possible to filter out unwanted senders.</p>\n<p>Verifying sender addresses is not possible using the MX record, since there is no guarantee the same host is used for receiving and sending mail.\nThe simplest solution is to publish the sending address in a seperate DNS record:</p>\n<pre><code>@ TXT v=spf1 ip4:65.109.172.162 ip6:2a01:4f9:c011:841a:b01d::1 -all\n; Roughly:\n;   allow from 65.109.172.162\n;   allow from 2a01:4f9:c011:841a:b01d::1\n;   deny otherwise</code></pre>\n<p>However, that&#39;s not quite enough for the email empire.\nBig-tech also wants the email body to be signed with a cryptographic key published via a (DKIM) DNS record.\nThis requires adding a step to sending mails, usually as a plugin for the MTA.</p>\n<p>While I rag on big-tech a lot, but this is actually a sensible policy:\nSPF can only verify the MAIL FROM, since forwarding the email will chance the source IP address.\nDKIM signatures are attached to the message and can be used to verify the original sender (the &quot;From&quot; address) of a message,\nwhich is what&#39;s actually shown to the user in most cases.</p>\n<p><em>However</em>, both of these don&#39;t actually prevent spam, because spammers can just set up a few TXT records.\nBig-tech also requires the sender&#39;s HELO hostname to be consistent with their IP address, via both forward and reverse DNS.\nThis helps prevent compromised devices from spewing out junk:\na smart TV is unlikely to have a meaningful PTR record, and if it does, that hostname won&#39;t resolve back to it&#39;s address.</p>\n<p>... unfortunately this policy also makes it impossible to directly send mail from most residential internet connections unless you own the address block.\nOf course, the solution is to pay a big-tech company money to relay your emails.\nIf you don&#39;t like this, find a mail provider with more permissive rules:\nthe only reason big-tech is able to keep their racket running that five or so companies control 99% of email.</p>\n<h2 id=\"the-message\"><em>The message</em></h2>\n<p>This is where SMTP stops being so simple.\nLet&#39;s look at the simplest possible email once it&#39;s been delivered:</p>\n<pre><code>Return-Path: &lt;alex@there&gt;\nDelivered-To: bob@here\nReceived: from here\n        by here with LMTP\n        id bs05E10S7Go4VQMAHrglgg\n        (envelope-from &lt;alex@there&gt;)\n        for &lt;bob@here&gt;; Thu, 05 Nov 2026 05:21:33 +0000\nDKIM-Filter: OpenDKIM Filter v2.11.0 here B05E67CD18\nReceived-SPF: None (mailfrom) identity=mailfrom; client-ip=313.33.33.337;\n        helo=there; envelope-from=alex@there; receiver=here\nReceived: from there (unknown [313.33.333.337])\n        by here (Postfix) with SMTP id B05E67CD18\n        for &lt;bob@here&gt;; Thu, 05 Nov 2026 05:20:42 +0000 (UTC)\nFrom: alex@there\nTo: bob@here\n\nHello, World!</code></pre>\n<p>The format of the headers is superficially similar to HTTP headers,\nexcept that no line should exceed 78 bytes. (without the CRLF line terminator)\nOverlong headers are broken up and newly created lines are prefixed with whitespace to indicate that they are a continuation of the last header.</p>\n<p>Mail software generally preppends headers to the start of a message, so it&#39;s helpful to read them backwards.\n&quot;From&quot; and &quot;to&quot; are fairly self explanatory.\nNext, the &quot;received&quot; header contains a note from the receiving MTA:\nit includes the source&#39;s HELO name, IP address, RCPT TO and a timestamp.</p>\n<p>The MTA then performed SPF and DKIM checks, which came up empty:\nThere&#39;s no signature and the MAIL FROM hostname is not publically resolvable.</p>\n<p>The LDA added another &quot;received&quot; header, although it&#39;s not very helpful.\nMore importantly, it tacked on the &quot;return-path&quot; with the original MAIL FROM address and recorded the mailbox the message was delivered to.</p>\n<p><em>However, the body isn&#39;t always plain text.</em>\nThis is an email that includes formatting:</p>\n<pre><code>[...]\nMIME-Version: 1.0\nContent-Type: multipart/alternative;\n boundary=----IX71FHL6PHA0538LS1WKT2W9SF7S8X\nContent-Transfer-Encoding: 7bit\n\n------IX71FHL6PHA0538LS1WKT2W9SF7S8X\nContent-Type: text/plain;\n charset=utf-8\nContent-Transfer-Encoding: quoted-printable\n\nHello, World! I can do bold text!\n\n------IX71FHL6PHA0538LS1WKT2W9SF7S8X\nContent-Type: text/html;\n charset=utf-8\nContent-Transfer-Encoding: quoted-printable\n\n&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;body&gt;&lt;div dir=3D&quot;auto&quot;&gt;Hello, world! I can do &lt;b&gt;bold&lt;=\n/b&gt; text&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;\n\n------IX71FHL6PHA0538LS1WKT2W9SF7S8X--</code></pre>\n<p>That&#39;s right, it&#39;s a web page!</p>\n<p>However, since not all email clients can understand HTML, the message also includes a plain text version.\nThis is done using MIME&#39;s &quot;multipart&quot; encoding, in this case, multipart/alternative, which indicates all the\nversions are functionally equivalent.</p>\n<p>MIME&#39;s version number has been stuck at 1.0 since 1996.</p>\n<p>The delimiter is a randomly chosen string, which allows multiple multiparts to be nested inside without escaping.\nEach section of the message has it&#39;s own headers, in this case, indicating that it&#39;s sent in the quoted-printable encoding.\nThis allows the email message to contain any bytes without exposing the MTA to scary things like non-seven-bit ASCII:\nremember, the SMTP is 45 years old.</p>\n<p>In quoted-printable, equal signs are used as the escape character: if followed by two hex digits, it decodes to that byte.\nIf followed by a newline, both characters are removed.\nThis is used to break long lines that could otherwise cause trouble.</p>\n<p>In this email, &quot;=3D&quot; becomes a literal equal sign and both lines are joined together.\nIf you&#39;ve ever seen an email with stray equals or missing one or two characters ~ every 80 bytes, broken quoted-printable decoding is usually the culprit.</p>\n<p>The second &quot;content-transfer-encoding&quot; is base64, which is used for binary files like attached images:</p>\n<pre><code>MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=&quot;5ZTNvId/H+rlk7Fr&quot;\nContent-Disposition: inline\n\n--5ZTNvId/H+rlk7Fr\nContent-Type: text/plain; charset=us-ascii\nContent-Disposition: inline\n\nCheck out this file:\n\n--5ZTNvId/H+rlk7Fr\nContent-Type: application/octet-stream\nContent-Disposition: attachment; filename=&quot;file.bin&quot;\nContent-Transfer-Encoding: base64\n\nJ7mtSdbQItOAi345nwaNkkTXrnDIRPA0DSwhbSAOwm2C/KoHjQIotY9lnJRMBRk9InQaHOxL\nbb7DGd9EN6uRpjvCbox9xblAh3CxH7sl+YAkYcKw1V100RpBwMhgaXfUJBB3oRkLffgRwEyK\nv9qFBLp9zZ+SiRJoRWbA4aZLexPhHZ35vFROVKYtiAeMlD1s15v3kPZvEADam0e45BoSaqmp\n1S3z3b5wBIFHJUxQULD589MKaFx2Z2A+91pl/pbZWmZkzt55D/hZ05kjUUbXUnDnTYAQE2Gk\nWnN+SnrQvfEO+Tz7AdrbLD1q2DgwWW+k0cVJLKjdwRxesGhAkQCZfHVrno6R4iXjTbInIbQv\nhXzQiV840iUiUhk282WADd1ffJ0sot2Waf7XHLIE1lZVFQ3iGofYbw8pZlg3sb35AnIWPZKv\nfbC6Yh95RV23R4K2NHeBX1rpl4bSSiftnD2RbsBzv7cgw/6M/Lj3O40NFGAaUC+J7TpAaXdi\ntvlPsNQhMo8QRf/ub7WK42cPUlz1fKq1k1pzGN96YOsE5azMfF4vLANtbtbVmLIp2WmgBk0P\n9IGMWy/xIAe0cOh+bqzru2+ojJGgx9uX4VSTP9BaTOwkVX5+rQfpp1qJodtHiO8sHw6Pg+Mg\nWcpqQPC7118ccuT44cVpIRkwOSoJzsW++WM=\n\n--5ZTNvId/H+rlk7Fr--</code></pre>\n<p>This is why size limits are often disappointing:\nthe email will be 33% larger than the attached file.\nMore efficient encodings (raw binary data) are supported by some MTAs, but may have to be converted to base64 somewhere down the path...\nwhich would break DKIM signing.</p>\n<p><em>Generally</em>:</p>\n<ul><li>No encoding (&quot;7-bit&quot;) can be used if the message has short lines and fits in low-bit ASCII. However, &quot;7-bit&quot; is mostly seen as a null encoding for already encoded multipart containers.</li><li>Quoted-printable if the message is mostly text, but has something that risks breaking ancient software.</li><li>Base64 for binary data.</li></ul>\n<h2 id=\"about-tls\"><em>About TLS</em></h2>\n<p>The SSL/TLS used by mail clients is effectively the same as for a browser:\nthe mail provider must go to a certificate authority, prove their identity and get a certificate..\nAlgorithms and ciphers are disabled at the slightest hint they may be insecure.</p>\n<p>However, MTAs operates on &quot;trusted&quot; networks...\nalthough it&#39;s less that an attacker can&#39;t get access to internet traffic, but that if they could,\nit would be possible for them to pass an ACME challenge and take out a trusted certificate.</p>\n<p>As a result, the goal is mostly to protect against passive eavesdropping:\nmost sysadmins don&#39;t bother dealing with a CA and use self-signed certificates.\n(it&#39;s not like CAs have a good track record: <a href=\"https://en.wikipedia.org/wiki/EMudhra\" rel=\"nofollow ugc noopener\">4</a>)</p>\n<p>Another weird thing about email is that MTAs don&#39;t use a separate TLS port.\nAll connections on port 25 start as plaintext, then the sender issues a STARTTLS command and hands over the connection to a SSL/TLS library.\nIt&#39;s somewhat janky, but it allows servers to attempt to use encryption and cleanly fall back if it&#39;s not supported.</p>\n<p>Such an approach isn&#39;t great for submissions, since a fall back would leak the password...\nand baddies on shared networks or nosy residential ISPs can strip out the STARTTLS command.\nFor this case, it&#39;s best to default use the dedicated SSL submission port: 465.</p>\n<p>(This port actually has a bit of a history, with it being deprecated in favor of STARTTLS\nbefore being re-endorsed once we realized using optional SSL for passwords was a bad idea.)</p>\n<h2 id=\"so-what\"><em>So what??</em></h2>\n<p>Unless you write email related software or run infrastructure, most of this information is profoundly useless.\nHowever, there are a few things you might want to remember.</p>\n<p><em>The underlying protocols allow five days for delivery</em>, and it can sometimes take longer.\nSince users expect delivery in seconds and most emails are at least somewhat time sensitive,\nsome MTAs are configured to send out delay notification if a message is taking a while.</p>\n<p>You may want to find out if yours does this before assuming the recipient is ignoring you.</p>\n<p><em>Emails are digital postcards</em>.</p>\n<p>A message will be stored and forwarded by multiple systems in plaintext.\nAnyone on the network path may be able to read your email:\nSSL/TLS is not universally supported and can trivially be stripped out by active attackers.</p>\n<p>This is an inherent part of email: there&#39;s no way to tack-on strong encryption without breaking existing clients.\nIf you need a guarantee of privacy, you must encrypt the message before sending, and the recipient must decrypt it themselves.\nBe careful with built-in tools like PGP:\nthese generally make it way too easy to accidentally hit &quot;reply-all&quot; without encrypting, in addition to other flaws like exposing the subject line.</p>\n<p>PGP stuff</p>\n<p>Since publication, multiple people have written to me explaining how obfuscating the subject line (or warning if the user fills it out)\nis completly unreasonable to expect from a for a self-proclaimed privacy tool.\nAt least in my eyes, &quot;encrypted messaging&quot; means encrypted, not 90% encrypted and 10% plaintext.</p>\n<p>The lack of deniablity and forward secrecy can be excused as limitiations of email&#39;s store-and-forward architecture...\nbut default plaintext and making no attempt to encrypt certain the subject line or attachments is a recipe for disaster:\nat least with vanilla email, people know it is not encrypted.</p>\n<p>&quot;Encrypted&quot; email providers are largely snake oil.\nWhile the message store can encrypt messages and a custom MUA could decrypt them, the MTA must have access to plaintext.\nAs a result, it provides minimal to no security against most attack vectors despite the &quot;millitary grade encryption&quot;.\nThe only way to fix email would be to get everyone to agree to switch to an end-to-end encrypted protocol...\nbut the whole point of email is universal compatability:\nencrypted messaging can exist, but encrypted email is contradictory.</p>\n<p>The best hope is to find a mail provider that can be trusted not to snoop messages.\nThat is to say, not an Advertising company (google) or one that&#39;s been pushing hard for LLMs (microsoft / apple):\nboth of these businesses create strong incentives to read your messages.\nAlthough you&#39;ll still have to hope whoever you are communicating with isn&#39;t beign snooped on by their provider.</p>\n<p><em>Worse, DKIM signatures</em> act as a lifelong proof that an email came from your provider&#39;s servers, even if a message is years old and has no clear chain of custody.\nThis makes leaked, hacked, or snooped emails ideal extortion material:\nsince the bad actor can trivially prove they haven&#39;t been fabricated.</p>\n<p>This property, called non-repudiation, is generally not desirable for private messaging systems.\nAvoiding signing not an option if you want to interoperate with big-tech, but it is possible to regularly rotate and publish private keys.\nBefore they key is published, the signature can be trusted to verify it is legitimate.\nHowever, once the key has been published, the signature can been forged by anyone and is rendered retroactively untrustworthy.</p>\n<p>Since authentication is checked during delivery by the MTA and LDA, this doesn&#39;t affect how the email will be handled.\nHowever, it will cast doubt on the authenticity of leaked messages since the signature could have been forged with minimal effort.</p>\n<p>While key rotation is common practice, most mail providers don&#39;t publish their old private keys,\nso the signature is still trustworthy (modulo the service being hacked).\nI would advise against emailing something you wouldn&#39;t be comfortable reading out in public.</p>\n<h1 id=\"related\"><em>Related</em>:</h1>\n<ul><li><a href=\"https://www.rfc-editor.org/info/rfc821/\" rel=\"nofollow ugc noopener\">https://www.rfc-editor.org/info/rfc821/</a>: Original SMTP</li><li><a href=\"https://www.rfc-editor.org/info/rfc2045/\" rel=\"nofollow ugc noopener\">https://www.rfc-editor.org/info/rfc2045/</a>: MIME extended message format</li><li><a href=\"https://www.rfc-editor.org/info/rfc7208/\" rel=\"nofollow ugc noopener\">https://www.rfc-editor.org/info/rfc7208/</a>: SPF Authentication</li><li><a href=\"https://www.rfc-editor.org/info/rfc6376/\" rel=\"nofollow ugc noopener\">https://www.rfc-editor.org/info/rfc6376/</a>: DKIM signing</li></ul>","headings":[{"level":1,"text":"*A bit about email*","id":"a-bit-about-email"},{"level":2,"text":"*SMTP*","id":"smtp"},{"level":2,"text":"*Authentication*","id":"authentication"},{"level":2,"text":"*The message*","id":"the-message"},{"level":2,"text":"*About TLS*","id":"about-tls"},{"level":2,"text":"*So what??*","id":"so-what"},{"level":1,"text":"*Related*:","id":"related"}]}}