Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unit test email sending?

I would like to test my email sending functionality using .NET (C#) framework or any compatible library, any suggestion how to do it?

like image 664
GigaPr Avatar asked Sep 06 '25 13:09

GigaPr


1 Answers

If you need test sending e-mail only, you can configure your .config file like this

<system.net>
    <mailSettings>
        <smtp deliveryMethod="SpecifiedPickupDirectory">
            <specifiedPickupDirectory pickupDirectoryLocation="C:\TempMail" />
        </smtp>
    </mailSettings>
</system.net>

With these settings your messages are not sent over the network, but are dropped as physical files with .eml extension in the folder you configured in the pickupDirectoryLocation attribute. You can check them with the help of classes in the System.IO namespace.

<smtp> Element (Network Settings)

like image 186
whyleee Avatar answered Sep 08 '25 02:09

whyleee