Why is ASP.NET SmtpClient.Send() making my site unavailable?
I have an ASP MVC 2 application, through which I occasionally send emails using SmtpClient.Send(). Typically, emails are sent out in batches of between 1 and 50 emails, with hours or even days passing between batches. I have this all set up so that the emails are actually sending just fine. But, the problem is that when the emails are sent, my site suddenly becomes unavailable for about 15 minutes, and I have no idea why.
My site is hosted on a shared, Windows 2008 server with a third-party web host.
开发者_JAVA技巧Here is the relevant section in my web.config file, edited for privacy:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="fromemail@doman.com">
<network host="mail.DOMAIN.COM" userName="username" password="password"/>
</smtp>
</mailSettings>
</system.net>
Does anyone have any thoughts or ideas as to why this might be happening? I've been trying to reaserch it and Google it for some time now, but I'm just not coming up with anything.
This really could be many different things but..
The first thing I suggest you do is enable ASP.NET Health Monitoring on your site. This should hopefully help you gain visibility of the exception that is causing this issue (A guide to using Health Monitoring).
For obvious reasons be sure not to choose the Mail Provider to send you your exceptions - perhaps use the SQL provider or write a custom provider that writes to a file.
I would also ask your hosts to look into the Event Log for any information that may be of value.
Hope that helps.
E-mail can be an expensive operation. Have you considered using the asynchronous e-mail send so that the process does not block your main thread?
精彩评论