When developing a system that sends mails, often the mails shouldn’t be sent for real when testing. Instead they should be made available for investigation. Fortunately, that functionality is built in with the .NET SmtpClient.
There is even no need to change the code. It’s just a matter of configuration. Add the following lines to the app.config (or web.config for web applications)
<system.net><mailSettings><smtpdeliveryMethod="SpecifiedPickupDirectory"from="firstname.lastname@example.org"><specifiedPickupDirectorypickupDirectoryLocation="c:\temp"/><!-- The network host setting isn't used, but without it an exception occurs when disposing of the SmtpClient.--><networkhost="localhost"/></smtp></mailSettings></system.net>
The pickup directory setting is meant to be used with a local mail server that watches a directory for new mails. I have no mail server watching my c:\temp directory. Instead, the mails are just dropped there as .eml-files that can be opened using a mail program (e.g. outlook).
In a perfect Scrum world, the team tests everything themselves. I think that misses an important point – the developers have a code-centric view on the domain. Good testing requires a user- or business-centric view on the domain. I think that it is impossible to both have a deep understanding of the code and to be a good tester.
That doesn’t relieve the developers from tests – developers having any pride in what they do of course unit test all their code. To get high quality software unit tests (whether automated or not, I’ll leave that discussion outside this post) is important, but not alone sufficient. There have to be system level tests and user/acceptance tests too.