It's not just for testing.
We're using it in production for two reasons: performance and availability.
If you have an Exchange server, it's very easy to send those saved mails later by just copying the .eml
files to a certain directory on the Exchange server.
Why would you want to do this?
Because the default way (using the SmtpClient
class to send the mail directly to the SMTP server) has two disadvantages:
- Your app has to establish a connection to the SMTP server (which takes time) for each and every single mail
- if the SMTP server is offline, it doesn't work
We do have an Exchange server, so we're sending mails by having our application server save them as .eml
files in a local directory.
(fortunately, we had a central "send mail" method instead of directly using SmtpClient
in a bazillion places, so we just had to change a few lines in that single method to make sure all mails go to the local directory)
That's all as far as our application server is concerned.
For our application server, "sending" a mail is faster now because it's just a local write. Plus, it works the same in case the Exchange server is offline.
So, what happens after the .eml
files are saved in the app server's local directory?
We have a (separate) simple C# app which runs each minute via Windows Task Scheduler and does the following:
- check if the Exchange server's pickup directory exists and is writable
- if yes, move all
.eml
files from the local directory to the Exchange pickup directory