This is posted as a hint to anyone having trouble with sending the email message for an exceptions as outlined in Chapter 18.
For me, the code in the book worked perfectly on my local machine but when I deployed to my web host (MyindowsHosting.com) I could not get it to send the "exception emails" The code for the login response and contact response did work on the web site. I spent about a week trying to figure out how to get the "exception e-mail" to work and finally, out of desperation, tried the following:
I changed the code in the Global.asax module as follows:
1) Added <%@ Import Namespace="System.Net"%>
2) Made the following change in the Application_Error Handler:
Removed the following two statements:
// SmtpClient mySmtpClient = new SmtpClient();
// SmtpClient mySmtpClient = new SmtpClient("smtp.gmail.com", 587);
And replaced withthe following (The same code as in the Controls.
// Required to change the code in "Beginning Asp.Net 4.5.1 in C# and VB
// to the following in order for it to send mail on My WindowsHosting Site1
SmtpClient mySmtpClient = new SmtpClient("smtp.gmail.com", 587);
mySmtpClient.UseDefaultCredentials = false;
mySmtpClient.Credentials = new
mySmtpClient.EnableSsl = true;
mySmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
This worked for me and I hope this hint may help someone else out.