I
InnoCreate
Hi Everyone,
I've added an error handler to some code and as part for the routine
it logs to the application log and then sends the administrator an
email. For some reason this email isn't actually being sent until the
application is exited. I can step through the code and when i call the
smptclient.send(message) the code executes without exception but it's
not until i exit the application that i see the norton antivirus email
icon in the system tray showing the email sending. Why isn't the
message being sent when i call the smtpclient.send(message)?
Here's an excert of my code.
Imports System.Net.Mail
Public Class ErrorHandle
Public Shared Sub LogError(ByVal ex As Exception)
' Log to event log
'My.Application.Log.WriteException(ex, TraceEventType.Error,
"ApplicationName Error Handler")
' Send error email
Dim smtp As New SmtpClient(My.Settings.MailServer)
Try
Dim mailAddresses As String =
My.Settings.ErrorEmailAddress
Dim errorMessage As New MailMessage(mailAddresses,
My.Settings.ErrorEmailAddress)
errorMessage.Body = ex.Message
errorMessage.Subject = My.Settings.InstanceName & "
Application Error Email"
smtp.Send(errorMessage)
Catch exMail As Exception
My.Application.Log.WriteException(ex)
Finally
smtp = Nothing
End Try
End Sub
End Class
Regards,
James
I've added an error handler to some code and as part for the routine
it logs to the application log and then sends the administrator an
email. For some reason this email isn't actually being sent until the
application is exited. I can step through the code and when i call the
smptclient.send(message) the code executes without exception but it's
not until i exit the application that i see the norton antivirus email
icon in the system tray showing the email sending. Why isn't the
message being sent when i call the smtpclient.send(message)?
Here's an excert of my code.
Imports System.Net.Mail
Public Class ErrorHandle
Public Shared Sub LogError(ByVal ex As Exception)
' Log to event log
'My.Application.Log.WriteException(ex, TraceEventType.Error,
"ApplicationName Error Handler")
' Send error email
Dim smtp As New SmtpClient(My.Settings.MailServer)
Try
Dim mailAddresses As String =
My.Settings.ErrorEmailAddress
Dim errorMessage As New MailMessage(mailAddresses,
My.Settings.ErrorEmailAddress)
errorMessage.Body = ex.Message
errorMessage.Subject = My.Settings.InstanceName & "
Application Error Email"
smtp.Send(errorMessage)
Catch exMail As Exception
My.Application.Log.WriteException(ex)
Finally
smtp = Nothing
End Try
End Sub
End Class
Regards,
James