Hacker News new | past | comments | ask | show | jobs | submit login

I use a simple local catch-all SMTP server for testing. I install it on my test machine listening on some non-SMTP port (default is 2000), and then use iptables to make all connection attempts to port 25 end up at the catch-all server.

Here's the iptable command: "iptables -t nat -A OUTPUT -p tcp --dport 25 -j REDIRECT --to-port 2000"

The catch-all server is ridiculously simple. It just responds with a "220 hello" when connected to, and then just reads input line by line, logging all input to a file. It only knows about two SMTP commands: DATA and QUIT.

On QUIT it sends "221 bye" and closes the connection.

On DATA it sends "354 send the message" and then just reads the data and logs it to the file.

Anything else? It just sends "250 OK".

Note that this is pretty useless if what you are trying to test is a mail client, because you cannot test error cases. The purpose of this SMTP catch-all is for testing the content of messages your software sends, not for testing the process of mailing itself.

Each connection is logged to a separate file.

The source is a single Java file. Here it is if anyone wants it [1]. "javac SmtpSink.java" to compile. "java SmtpSink" to run. Messages are stored in the "msgs" directory, which you should make before running it.

[1] https://pastebin.com/WqkS7jNH




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: