

Ask HN: how to unit/integration test app that sends email? - tapostrophemo

I'm adding a "register-&#62;confirm email-&#62;reg. complete" functionality to a web app I'm writing. I'd like to be able to unit/integration test my email-sending code.<p>I don't want to actually send emails. In fact, I'd like to keep all this local to my machine (or at least to my home network). And if I can avoid it, I don't want to install/configure sendmail/qmail/postfix/etc.; i.e., I don't want to install a real email server.<p>Is there a test SMTP server anyone knows of that's quick and easy to install (on Linux)? Or a clever hack using honeyd to fake out the SMTP communication?
======
SwellJoe
You don't need to get clever here. Any SMTP server will deliver locally if you
just give it a username.

So, any mail server will do. Just configure it to only accept mail from/for
localhost. I know that Perl and Python both have good small SMTP servers
available, and I imagine most dynamic languages would also (if it even matters
what language it is in). So, you could use one of those, fire it up on a high
port as part of your test process and send a message to the user running the
test (which would then deliver to the users Maildir or whatever, based on
configuration).

But I would just use Postfix. It's small, really easy to configure, and can be
installed on most modern Linux distros with one command. It can easily be
configured as I've suggested (set it to listen only on loopback, and set the
destination to only localhost, and then send mail to "joe" rather than
"joe@domain.tld").

------
jedediah
Since you're writing a web app, there are very likely many well-tested
libraries for sending mail. I suggest using one of these, then stub the
interface to the librart and make sure your code is using the correct API when
talking to the library.

