High performance SMTP client to send email written in Perl and using Linux epoll mechanism.
Written in 2006 or 2007 before the Global Financial Crisis to send emails to a very large list of opt-in contacts.
What's unusual about it are several things:
- It uses the Linux kernel
epoll
mechanism to handle events instead of the more commonselect
(which Perl supports natively), by invoking the kernelepoll
APIs directly via syscalls.Epoll
was new at the time, and state of the art, but also more complicated to set up and use. - The company had six Class C (ie
/24
) blocks of IP addresses (roughly 1500, worth a small fortune today), and the code cycles through the addresses used to open the connection to the SMTP server while running. It's a good demonstration of dynamic adjustment of network settings. - It is 100% Perl with few dependencies.
- It is extremely efficient and fast. On a modest single core Pentium 4 with 1GB RAM and a T1-level connection, it could send around 200K emails per hour.
The code is sanitized but otherwise unmodified, since that would destroy the context of using the various mechanisms.
On startup, it spawns child processes (70 was the default, tuned to the hardware it ran on) to send emails. The parent process calculates the emails to send, collates them by recipient domain, then dispatches them to each child to send. The child receives the instructions, opens an SMTP connection to the recipient domain, and sends the email. It then sends a response back to the parent, which logs the exchange.
There were plans to convert the hard-coded version you see into a general solution with a web-based front end.
There is also an SMTP server script to process replies.