A walkthrough on how to implement and deploy your own disposable email server from scratch.
As a loyal user of 10minutemail, I always wondered how hard it would be to implement and set up your own disposable email server — one used solely for posting your email address to one of those “we’d love to know more about you before we let you download our open-source software” forms, registering to trial periods, and local tests for my other weekend projects. As it turns out, implementing such a server is a surprisingly smooth and gratifying experience!
The result of this small personal hackathon is edgemail, an open-source disposable email server. In this post, you’ll see how to write and deploy one yourself. A public instance of edgemail is hosted here.
Simple Mail Transfer Protocol (SMTP) is old. I was also surprised to discover that for such a battle-tested and reliable protocol, there aren’t that many resources to learn about its details, especially if you would like to implement it yourself. In fact, all “build your own SMTP” tutorials basically start with “install Postfix” — which is a fully-fledged, production-grade SMTP server! Let’s start with the basics instead.
SMTP is an application layer protocol that runs on top of a transport layer, which is customarily TCP. SMTP is text-based and connection-oriented, which fortunately makes it human-readable. An SMTP transaction is simply a sequence of request-reply messages.
An example conversation between a client and a server may look like this:
Server->Client: 220 edgemail server reporting for duty Client->Server: HELO smtp.example.com Server->Client: 250-smtp.example.com Hello user Client->Server: MAIL FROM: Server->Client: 250 Ok Client->Server: RCPT TO: Server->Client: 250 Ok Client->Server: DATA Server->Client: 354 End data with . Client->Server: From: "Robert Client->Server: To: "Rosie Client->Server: Date: Wed, 19 Apr 2023, 12:30:34 Client->Server: Subject: Hi Rosie! Client->Server: Hi Rosie! How are you today? Client->Server: . Server->Client: 250 Ok Client->Server: QUIT Server->Client: 221 Bye
This simple example is enough to start sketching an implementation of the server, which would be a quite simple state machine capable of handling a few commands: greeting the user, and receiving mail. Sending mail is more complex, and won’t be covered in this blog post. Fortunately, we do not need to ever send mail from our disposable server — it’s only going to be used as a throwaway address used for registering to unwanted newsletters.
The project’s name is edgemail, which is a tribute to the fact that it provides low latency for its users thanks to using an edge-native database. More on that in a few paragraphs!
The server will be implemented as 3 separate layers:
SMTP state machine, responsible for handling SMTP communication
Database for storing mail
Client for browsing mail
SMTP is a rather complicated standard, but fortunately for disposable email purposes we can ignore all the extensions, authentication, authorization, etc, focusing on just being able to receive mail. The (slightly simplified) figure below shows how our server is going to operate.