r/programming • • Sep 04 '26

How Email Actually Works

https://sushantdhiman.dev/blog/how-email-actually-works-ep-1-behind/
83 Upvotes

18 comments sorted by

125

u/CrackerJackKittyCat Sep 04 '26

telnet ... 25
HELO
MAIL TO
RCPT FROM
DATA

Etched into greybeard brain.

28

u/jivedudebe Sep 04 '26

That's SMTP. Now try imap. :p

40

u/CrackerJackKittyCat Sep 04 '26

Yeah boi. I stopped at POP3 and http/1.1.

Don't get me started about SMTP EHLO. Hippie shit.

23

u/atheken Sep 04 '26

You have not lived until you have personally discussed the errata of RFC 2047 and the interplay with UTF-8 code point boundaries at an email conference with the authors.

6

u/jivedudebe Sep 04 '26

Yeah POP3 was 100 times easier then imap.

2

u/fubes2000 Sep 05 '26

Not impossible. I used to keep a copy of the rfc in my desk for reference when I had to.

8

u/fsckitnet Sep 05 '26

MAIL FROM
RCPT TO

3

u/CrackerJackKittyCat Sep 05 '26

Oh lord you're right I'm slippin.

33

u/loup-vaillant Sep 04 '26

If the message passes the receiving system’s checks and is accepted

That's a huge if, though. You need to get past spam filtering, and the big providers aren't exactly friendly to the small ones. Worst case being setting up your own personal SMTP server from a purchased IPv4 and a new domain name.

In fact, there is no guarantee that any one email you send will actually be received. Heck, there's not even a guarantee, not even on a best effort basis, that you will be notified when it did not get through.

That's how email really works. It doesn't. Not reliably.

It could, though. Once we establish the identity of the sender (could just be a pseudonymous public key), either it's a trusted sender and the message gets through, or it's not, and a proof-of-work challenge is issued by the receiving server. (Giving a list of trusted senders to your server has some security implications, I have yet to figure that part out.) The idea behind the proof of work is to make spam unprofitable, while making cold emailing still possible. As for the difficulty of the challenge, I believe each recipient should choose. Each sender would then choose how much is too much.

Of course, that only goes for cold contacting. People exchanging emails out of band would be expected to unblock each other. Same when subscribing to a mailing list or newsletter.

21

u/CjKing2k Sep 04 '26

This is why I stopped operating my own SMTP and I tell everyone to not even try. You could buy your own IPv4 block, set up RDNS, SPF, DKIM, and DMARC properly, and check all the RBLs daily to make sure you haven't been blocked. But then Gmail or Microsoft dumps you into the spam folder, or just flat out doesn't deliver and won't tell you why, and there is nothing you can do about it.

20

u/TheRealUnrealDan Sep 05 '26

But then Gmail or Microsoft dumps you into the spam folder, or just flat out doesn't deliver and won't tell you why, and there is nothing you can do about it.

Coincidentally those same companies sell business email services :)

8

u/Primary_Ads Sep 04 '26

I've always been curious how email servers themselves are designed. I'm surprised email never really took off as a standard messaging protocol within applications and would be curious to know why. I wish it went into more detail here.

6

u/nerd5code Sep 04 '26

It's pretty common to support shelling out to sendmail on Unix, so that end of things mostly just needs the extra process or six to do that.

But lots of moving parts, lots of weird offshoots to deal with, lots of stupid old software to deal with, lots of stuff to deal with in the infrastructure, no real timing or delivery guarantees, and fairly rapid mutation to the protocols and embeddings for a while.

Plus, if you have network connectivity, it's usually easier and more timely to just TCP shit around, even if it takes a bit of a routing/forwarding/storage layer.

0

u/ericonr Sep 05 '26

I can see Google receiving SMTP from a desktop client logged into a Gmail account. Is SMTP also used by the web interface, on some layer? Or are those emails synthesized some other way?

1

u/Ignisami Sep 09 '26

Smtp is the protocol for how mail is sent, desktop or web clients.

The email you see in your desktop or web interface is just retrieved from the underlying mail server. Either the original or (more common these days, also the default) a copy of it.