aspNetEmail

EmailMessage.SendASPNETException Method (String, String, String, String, MailFormat, Exception, ServerErrorSection[])

Automatically formats and sends an exception.

public static void SendASPNETException(
   string mailServer,
   string fromAddress,
   string toAddress,
   string subject,
   MailFormat bodyFormat,
   Exception exception,
   params ServerErrorSection[] sections
);

Parameters

mailServer
Mail Relay Server
fromAddress
From email address
toAddress
Recipient's email address
subject
Subject of the email
bodyFormat
Format of the email
exception
Exception to format
sections
ServerErrorSections to include in the email

Remarks

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.

Example

[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
            
            

See Also

EmailMessage Class | aspNetEmail Namespace | EmailMessage.SendASPNETException Overload List