# Simple smtp server

**URL:** <https://www.ruby-forum.com/t/simple-smtp-server/74559>\
**Category:** Ruby\
**Created:** [November 7, 2006, 10:48am UTC](https://www.ruby-forum.com/t/simple-smtp-server/74559 "2006-11-07T10:48:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 7, 2006, 10:48am UTC](https://www.ruby-forum.com/t/simple-smtp-server/74559/1 "2006-11-07T10:48:07Z")

</div>

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.

TIA  
MM

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 7, 2006, 10:50am UTC](https://www.ruby-forum.com/t/simple-smtp-server/74559/2 "2006-11-07T10:50:17Z")

</div>

On 10/30/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

I’ve written SMTP servers several times in Ruby and in C++. You’re not  
too  
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  
quick  
solution to a narrowly-defined problem?

I would start by reading RFC-821 and RFC-822. SMTP is a very old  
protocol,  
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  
automatic  
agents. It’s very simple to understand but deceptively difficult to  
implement, so don’t underrate it. It’s not like more modern protocols  
that  
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  
the  
protocol state machine (RFC-821). The creators of SMTP (one of whom was  
the  
late, great Jon Postel) were wise to split it into two documents.  
Headers  
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  
of  
the need to deal with all of the network and server-architecture  
headaches.  
You still have to deal with SMTP, although at some future point  
EventMachine  
should have built-in support for SMTP (as does Twisted, EM’s older  
brother  
in the Python world).

Good luck.
