Simple smtp server

Hello folks,

I’d like to understand if anybody has ever written a very simple smtp
server (supporting SSL authentication). I’d like to write an stmp proxy
for my own personal usage and I’m trying to understand where to start.


On 10/30/06, [email protected] [email protected] wrote:

I’ve written SMTP servers several times in Ruby and in C++. You’re not
specific about the point of the exercise. Are you looking to learn about
network programming and SMTP in particular? Or are you looking for a
solution to a narrowly-defined problem?

I would start by reading RFC-821 and RFC-822. SMTP is a very old
designed long before the dominance of IP and of TCP, and written to be
usable interactively by humans at a command prompt as well as by
agents. It’s very simple to understand but deceptively difficult to
implement, so don’t underrate it. It’s not like more modern protocols
may appear to have more functionality but are actually less complex
grammatically and easier to implement.

Keep the parsing of message headers (RFC-822) separate in your mind from
protocol state machine (RFC-821). The creators of SMTP (one of whom was
late, great Jon Postel) were wise to split it into two documents.
can be dealt with easily enough in Ruby with regular expressions but the
protocol stream is best dealt with as a FSM.

Look at the EventMachine library for a framework that will relieve you
the need to deal with all of the network and server-architecture
You still have to deal with SMTP, although at some future point
should have built-in support for SMTP (as does Twisted, EM’s older
in the Python world).

Good luck.