<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Brown Connie</title>
    <description>The latest articles on DEV Community by Brown Connie (@brown_connie_6a65da4327b8).</description>
    <link>https://dev.to/brown_connie_6a65da4327b8</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4244354%2F65e0c701-f907-41e9-bc4b-472543782657.jpg</url>
      <title>DEV Community: Brown Connie</title>
      <link>https://dev.to/brown_connie_6a65da4327b8</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brown_connie_6a65da4327b8"/>
    <language>en</language>
    <item>
      <title>Writing an SMTP server in Node.js with zero dependencies</title>
      <dc:creator>Brown Connie</dc:creator>
      <pubDate>Sat, 14 Nov 2026 11:36:59 +0000</pubDate>
      <link>https://dev.to/brown_connie_6a65da4327b8/writing-an-smtp-server-in-nodejs-with-zero-dependencies-2lbm</link>
      <guid>https://dev.to/brown_connie_6a65da4327b8/writing-an-smtp-server-in-nodejs-with-zero-dependencies-2lbm</guid>
      <description>&lt;p&gt;A disposable email service needs to &lt;em&gt;receive&lt;/em&gt; mail. There is no stdlib SMTP server in Node, and the npm options (smtp-server, mailparser) are fine — but I wanted zero dependencies, so I wrote the SMTP side myself. Here is the whole thing, reduced to what actually matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  The protocol is a line-based conversation
&lt;/h2&gt;

&lt;p&gt;SMTP is text. The client sends commands, one per line, and the server answers with a three-digit code plus a human-readable message. A minimal receive-only session looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;← &lt;span class="mi"&gt;220&lt;/span&gt; &lt;span class="n"&gt;mx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt; &lt;span class="no"&gt;ESMTP&lt;/span&gt;
→ &lt;span class="no"&gt;EHLO&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;
← &lt;span class="mi"&gt;250&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;mx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;
← &lt;span class="mi"&gt;250&lt;/span&gt; &lt;span class="no"&gt;SIZE&lt;/span&gt; &lt;span class="mi"&gt;10485760&lt;/span&gt;
→ &lt;span class="no"&gt;MAIL&lt;/span&gt; &lt;span class="no"&gt;FROM&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;alice&lt;/span&gt;@&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
← &lt;span class="mi"&gt;250&lt;/span&gt; &lt;span class="no"&gt;OK&lt;/span&gt;
→ &lt;span class="no"&gt;RCPT&lt;/span&gt; &lt;span class="no"&gt;TO&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;@&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
← &lt;span class="mi"&gt;250&lt;/span&gt; &lt;span class="no"&gt;OK&lt;/span&gt;
→ &lt;span class="no"&gt;DATA&lt;/span&gt;
← &lt;span class="mi"&gt;354&lt;/span&gt; &lt;span class="nc"&gt;End&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="n"&gt;with&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;CR&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;LF&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;CR&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;LF&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
→ &lt;span class="nc"&gt;Subject&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt;
→ &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;
→ &lt;span class="p"&gt;.&lt;/span&gt;
← &lt;span class="mi"&gt;250&lt;/span&gt; &lt;span class="no"&gt;OK&lt;/span&gt; &lt;span class="n"&gt;queued&lt;/span&gt;
→ &lt;span class="no"&gt;QUIT&lt;/span&gt;
← &lt;span class="mi"&gt;221&lt;/span&gt; &lt;span class="nc"&gt;Bye&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is the entire happy path. The state machine is: &lt;code&gt;IDLE → greeted → mailFrom → rcptTo → data → done&lt;/code&gt;. Each command is allowed only in the right state; anything else gets &lt;code&gt;503 Bad sequence of commands&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading lines correctly
&lt;/h2&gt;

&lt;p&gt;The trap: sockets do not deliver lines, they deliver chunks. You buffer bytes and split on &lt;code&gt;\r\n&lt;/code&gt;. Bare &lt;code&gt;\n&lt;/code&gt; shows up in the wild too, so tolerate both.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;sock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'data'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;buf&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'utf8'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'\r\n'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;buf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;handleLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trimEnd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the client switches to data mode, stop parsing lines as commands: everything until a line containing only &lt;code&gt;.&lt;/code&gt; is the message body.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dot-stuffing
&lt;/h2&gt;

&lt;p&gt;A message body may contain lines starting with &lt;code&gt;.&lt;/code&gt;. The client prefixes such lines with an extra dot, and the server removes one dot from any line starting with a dot. Skip this and mail containing a line like ".bye" gets corrupted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Size limits are not optional
&lt;/h2&gt;

&lt;p&gt;Without a cap, one client can POST you a 20 GB message. Advertise &lt;code&gt;SIZE 10485760&lt;/code&gt;, count bytes as they arrive, reply &lt;code&gt;552&lt;/code&gt; mid-stream when exceeded, and cap line length (998 bytes per RFC 5321).&lt;/p&gt;

&lt;h2&gt;
  
  
  Parsing the message
&lt;/h2&gt;

&lt;p&gt;A raw email is headers, a blank line, then the body. Headers can be folded (continuation starts with whitespace). &lt;code&gt;Content-Type&lt;/code&gt; says whether the body is text/plain, text/html, or multipart with a boundary. Split multipart bodies on &lt;code&gt;--boundary&lt;/code&gt; and decode each part's transfer encoding: quoted-printable (&lt;code&gt;=XX&lt;/code&gt;), base64, or raw 8-bit. Decode &lt;code&gt;=?UTF-8?B?...?=&lt;/code&gt; encoded words in the Subject.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I skipped (deliberately)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;TLS.&lt;/strong&gt; Transactional senders increasingly require STARTTLS; running plaintext SMTP behind Postfix on localhost is fine, a public port 25 without it is not.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SPF/DKIM/DMARC verification.&lt;/strong&gt; Inbound mail should be checked before delivery; that is a project of its own.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Queues and retries.&lt;/strong&gt; This server accepts or refuses; no store-and-forward.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The point was not to rebuild Postfix — it was to accept mail from a local relay, parse it, and put it in SQLite in a few hundred lines with zero dependencies.&lt;/p&gt;

&lt;h2&gt;
  
  
  The result
&lt;/h2&gt;

&lt;p&gt;The whole service — SMTP receiver, MIME parser, SQLite inboxes, web UI — is one Node.js file. If you want to see what it looks like end to end: &lt;strong&gt;&lt;a href="https://howtageek.com" rel="noopener noreferrer"&gt;https://howtageek.com&lt;/a&gt;&lt;/strong&gt;. The architecture write-up is here: &lt;a href="https://dev.to/brown_connie_6a65da4327b8/i-built-a-disposable-email-service-that-runs-on-one-nodejs-file-no-npm-dependencies-508j"&gt;I built a disposable email service that runs on one Node.js file&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Questions about the SMTP corners (dot-stuffing, 8BITMIME, pipelining) are welcome in the comments — I hit most of them the hard way.&lt;/p&gt;

</description>
      <category>nodenode</category>
    </item>
    <item>
      <title>I built a disposable email service that runs on one Node.js file — no npm dependencies</title>
      <dc:creator>Brown Connie</dc:creator>
      <pubDate>Sat, 14 Nov 2026 11:09:08 +0000</pubDate>
      <link>https://dev.to/brown_connie_6a65da4327b8/i-built-a-disposable-email-service-that-runs-on-one-nodejs-file-no-npm-dependencies-508j</link>
      <guid>https://dev.to/brown_connie_6a65da4327b8/i-built-a-disposable-email-service-that-runs-on-one-nodejs-file-no-npm-dependencies-508j</guid>
      <description>&lt;p&gt;Most "temp mail" sites are ad farms. I wanted one I could own, so I built it: a disposable inbox service where the entire server is a single Node.js file with zero npm dependencies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Demo:&lt;/strong&gt; &lt;a href="https://howtageek.com" rel="noopener noreferrer"&gt;https://howtageek.com&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The constraint
&lt;/h2&gt;

&lt;p&gt;I set one rule: no dependencies. No Express, no SMTP library, no ORM, no dotenv. Node 22 ships &lt;code&gt;node:sqlite&lt;/code&gt; and &lt;code&gt;node:net&lt;/code&gt; — that covers storage and SMTP. Everything else is the standard library.&lt;/p&gt;

&lt;p&gt;That leaves three jobs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Receive mail.&lt;/strong&gt; An SMTP server on port 2527 speaking just enough of RFC 5321 to accept a message.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parse it.&lt;/strong&gt; MIME multipart, base64/quoted-printable bodies, headers that wrap across lines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Store and serve it.&lt;/strong&gt; SQLite for the inbox, server-rendered HTML for the UI, a sliding TTL that deletes expired messages.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The SMTP bit
&lt;/h2&gt;

&lt;p&gt;The protocol is simpler than it looks. A session is a sequence of line-based commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;EHLO&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;
&lt;span class="no"&gt;MAIL&lt;/span&gt; &lt;span class="no"&gt;FROM&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;@&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="no"&gt;RCPT&lt;/span&gt; &lt;span class="no"&gt;TO&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;@&lt;span class="n"&gt;yourdomain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="no"&gt;DATA&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="no"&gt;QUIT&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You answer with three-digit codes, buffer until the lone &lt;code&gt;.&lt;/code&gt; line, then hand the message to the parser. The subtle parts are not the commands — they are line endings (bare LF vs CRLF), dot-stuffing (a line starting with &lt;code&gt;.&lt;/code&gt; is escaped), and the size limits you must enforce so one bad client cannot exhaust memory.&lt;/p&gt;

&lt;h2&gt;
  
  
  The MIME bit
&lt;/h2&gt;

&lt;p&gt;Modern mail is multipart: a plain-text alternative, an HTML alternative, sometimes attachments. Parsing means walking the header tree, reading &lt;code&gt;Content-Type: multipart/alternative; boundary="..."&lt;/code&gt;, and splitting on the boundary. Then decode the transfer encoding: quoted-printable for mostly-ASCII text, base64 for everything else.&lt;/p&gt;

&lt;p&gt;Two things bite:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Folded headers.&lt;/strong&gt; A long header continues on the next line if that line starts with whitespace. Join them before parsing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Charsets.&lt;/strong&gt; &lt;code&gt;=?UTF-8?B?...?=&lt;/code&gt; encoded words in the Subject line.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I render the HTML body inside a sandboxed iframe with scripts disabled — the raw mail is untrusted input, and a temp-mail viewer that executes remote CSS/JS is a phishing delivery system.&lt;/p&gt;

&lt;h2&gt;
  
  
  The TTL
&lt;/h2&gt;

&lt;p&gt;Each inbox is a session with an expiry timestamp. Every read pushes it forward (sliding TTL), and a small sweeper deletes expired messages and sessions. SQLite makes this trivial: one &lt;code&gt;DELETE FROM messages WHERE session_id IN (...)&lt;/code&gt; per sweep.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi-domain and the admin panel
&lt;/h2&gt;

&lt;p&gt;Domains are rows in a table. Each one gets an MX record pointing at the server; Postfix (or a raw port-25 relay) forwards every address on that domain to the embedded SMTP on 2527. Adding a domain is one form field. There is also an admin panel for ads, a Markdown blog, and settings — all server-rendered, no SPA.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why bother self-hosting
&lt;/h2&gt;

&lt;p&gt;Public temp-mail services see every confirmation email you receive — that is the business model. Self-hosting moves that trust boundary to a VPS you control. The trade-off is setup time: about five minutes (copy the folder, run it, point the MX record).&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do differently
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Start with a proper SMTP state machine from day one — retrofitting error handling into a happy-path parser is painful.&lt;/li&gt;
&lt;li&gt;Store raw RFC822 bytes alongside the parsed body; re-parsing is cheaper than losing data.&lt;/li&gt;
&lt;li&gt;Rate-limit per IP at the SMTP layer, not the HTTP layer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to poke at it: &lt;strong&gt;&lt;a href="https://howtageek.com" rel="noopener noreferrer"&gt;https://howtageek.com&lt;/a&gt;&lt;/strong&gt; — 17 domains, 10-minute inboxes, and the whole thing is one file. Happy to answer questions about the SMTP/MIME internals in the comments.&lt;/p&gt;

</description>
      <category>node</category>
    </item>
  </channel>
</rss>
