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.
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. Personal data/cookies will be used for personalization of ads. Our partners will collect data and use cookies for ad personalization and measurement
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checkbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.