Automatically formats and sends an exception.
Be sure to test this method, fully, before moving your code to the global.asax. Because errors are not raised from inside of the Application_Error method of the global.asax, any problems with your mail servers or email addresses may no be easily traced down.
If "{0}" (without the quotes) is found inside of the EmailMessage subject, aspNetEmail will replace {0} with the server error location.
[C#]
private void Page_Load(object sender, System.EventArgs e)
{
try
{
//do some work
//simulate an exception being thrown
Exception fakeException = new Exception( "this is a fake excpetion for testing.");
throw fakeException;
}
catch( Exception ex )
{
EmailMessage.SendASPNETException( "mail.mycompany.com", "me@mycompany.com", "you@yourcompany.com", null, MailFormat.Html, ex, ServerErrorSection.All );
}
}
[Visual Basic]
Private Sub Page_Load(sender As Object, e As System.EventArgs)
Try
'do some work
'simulate an exception being thrown
Dim fakeException As New Exception("this is a fake excpetion for testing.")
Throw fakeException
Catch ex As Exception
EmailMessage.SendASPNETException("mail.mycompany.com", "me@mycompany.com", "you@yourcompany.com", Nothing, MailFormat.Html, ex, ServerErrorSection.All)
End Try
End Sub 'Page_Load
EmailMessage Class | aspNetEmail Namespace | EmailMessage.SendASPNETException Overload List