system.net.mailmessage not sending until application exits - why?

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

InnoCreate

add

errorMessage.Dispose()

in your Finally

/LM













- Show quoted text -

Thanks luc - That seems to have done the trick. I should of realised
that from the way it was behaving.
 
I

InnoCreate

add

errorMessage.Dispose()

in your Finally

/LM













- Show quoted text -

Thanks luc - That seems to have done the trick. I should of realised
that from the way it was behaving.
 
G

Guest

Hello,

I'm having exactly the same problem, bu the 'dispose' solution didn't work
for me. I have installed an outbound mail scanner and I can't dissable it
(it's installed in the whole company) Because the application is a windows
service, I cant rely in sending the messages when the app finishes, so
anybody knows any other workaround for this problem?

Thanks,
Jacobo.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top