tags:

views:

45

answers:

1

I was setting up ELMAH to send email notifications of errors, and I discovered something interesting that caught me by surprise.

In my web.config, the elmah section was set up like so:

<elmah>
    <errorMail from="[email protected]"
               to="[email protected]"
               subject="Error Notification"
               smtpServer="localhost" />
</elmah>

This works fine on our IIS servers, and the emails are sent instantaneous. I assumed that when I ran my application in Visual Studio, ELMAH wouldn't know what to do with the localhost server since Cassini doesn't have a mail server configured. Lo and behold, I discovered when testing that theory that the error notification does in fact get sent. It takes a significantly longer amount of time (about 2 minutes, versus instantaneous on an IIS server or if I specify the mail server directly).

How does SmtpClient.Send() know which mail server to use when it's not explicitly specified?

I did some digging around with Reflector, and I suspect that it might be somewhere in SmtpTransport (possibly the GetConnection() method?).

A: 

Well, the answer wasn't nearly as exciting or interesting as I thought it might be. I had visions of complex mail server detection methods, but it turns out that I just have an SMTP Service running that is tied in to IIS on my local machine, which is why localhost works as the mail server in Cassini.

Funny how technology seems magical until you understand the inner workings of it :P

Ryan Rivest