frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

SMTP server from scratch in Go – FSM, raw TCP, and buffer-oriented I/O

3•Jyotishmoy•2h ago
I’ve been using AWS SES for a while and realized I treated SMTP as a black box. To understand the protocol better, I built an MTA (Mail Transfer Agent) from scratch in Go. It handles the full SMTP lifecycle (RFC 5321) using raw TCP sockets instead of high-level frameworks.

The Engineering Challenges:

Finite State Machine (FSM): SMTP is strictly stateful. I implemented an FSM to enforce command sequencing (e.g., preventing DATA before MAIL FROM). It ensures that protocol violations are caught at the socket level with proper 503 Bad Sequence codes.

Buffer-Oriented Processing: Used bufio.Scanner to handle the byte stream. The biggest hurdle was the DATA phase logic—properly detecting the \r\n.\r\n sequence while managing memory efficiently using strings.Builder.

Concurrency: Leveraged Go's Accept() loop to spawn independent goroutines for each session, ensuring that the relay latency to Gmail (via STARTTLS) doesn't block the listener.

ISP Workarounds: Configured to run on port 2525 by default to bypass the common ISP block on port 25.

Status Codes Implemented: I implemented a subset of RFC 5321 codes, including 220 (Service Ready), 354 (Start Input), and error handling for 501 (Syntax) and 451 (Local Error).

Why I built this: Most modern tutorials stop at "How to send an email with a library." I wanted to see how the "dot-stuffing" mechanism worked and how a server actually negotiates a multi-step handshake over a raw connection.

I’d love to hear about edge cases I might have missed—specifically around handling malformed headers or managing long-lived TCP connections under load.

Source Code: https://github.com/Jyotishmoy12/SMTP_Server

Tell HN: Ralph Giles has died (Xiph.org| Rust@Mozilla | Ghostscript)

281•ffworld•13h ago•12 comments

Ask HN: What would you recommend a vibe coder learn about how all this works?

16•alexdobrenko•14h ago•14 comments

SMTP server from scratch in Go – FSM, raw TCP, and buffer-oriented I/O

3•Jyotishmoy•2h ago•0 comments

Ask HN: What are you working on? (February 2026)

327•david927•4d ago•1124 comments

Ask HN: Did YouTube change how it handles uBlock?

13•tefloon69•15h ago•9 comments

Ask HN: Why is my Claude experience so bad? What am I doing wrong?

4•moomoo11•4h ago•4 comments

Ask HN: Better hardware means OpenAI, Anthropic, etc. are doomed in the future?

3•kart23•8h ago•4 comments

Ask HN: How do you audit LLM code in programming languages you don't know?

6•syx•17h ago•5 comments

Ask HN: Do sociotechnical pressures select for beneficial or harmful AI systems?

3•jerlendds•14h ago•1 comments

Ask HN: We're building a saving app for European savers and need GTM advice

3•AlePra00•15h ago•6 comments

Ask HN: What happens when capability decouples from credentials?

6•falsework•11h ago•3 comments

Ask HN: Tools to code using voice?

5•emerongi•21h ago•5 comments

Who discovered grokking and why is the name hard to find?

2•asmodeuslucifer•6h ago•0 comments

Ask HN: Are you using an agent orchestrator to write code?

32•gusmally•17h ago•45 comments

Ask HN: If your OpenClaw could do 1 thing it currently can't, what would it be?

5•stosssik•13h ago•3 comments

Ask HN: How do founders demo real product without exposing sensitive data?

4•legitimate_key•13h ago•6 comments

Ask HN: How do you "step through" your own anxiety?

5•schneak•13h ago•9 comments

Ask HN: Why are electronics still so unrecyclable?

70•alexandrehtrb•1d ago•137 comments

Ask HN: Would you use context-based "modes" in Instagram(work,study,sport,news)?

3•MatiasLaudonio•12h ago•2 comments

Ask HN: How much PTO do you get?

2•SunshineTheCat•12h ago•6 comments

Ask HN: Best practices for AI agent safety and privacy

2•mw1•13h ago•0 comments

Ask HN: How to build text-to-app platforms?

2•desperado1•13h ago•1 comments

Ask HN: GPT-5.3-Codex being silently routed to GPT-5.2?

4•tardis_thad•15h ago•2 comments

Ask HN: Has anyone achieved recursive self-improvement with agentic tools?

9•nycdatasci•1d ago•14 comments

Ask HN: What's the current state of ChatGPT Apps?

4•arthurlee•17h ago•1 comments

Ask HN: Is Prettier extension working for you in Cursor?

2•vldszn•18h ago•0 comments

Ask HN: Anyone else get bricked by the macOS update?

2•bix6•19h ago•1 comments

Ask HN: Dumping GitHub for Forgejo for a free and open source project

4•th0th•21h ago•4 comments

Ask HN: Why is everyone here so AI-hyped?

29•fandorin•2d ago•19 comments

Tell HN: GPT-5.3-codex is now available in the API

3•bigwheels•18h ago•0 comments