473,378 Members | 1,280 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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

Feb 25 '07 #1
4 1714
add

errorMessage.Dispose()

in your Finally

/LM

"InnoCreate" <Ja***@InnoCreate.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
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

Feb 25 '07 #2
On 25 Feb, 04:33, "Luc E. Mistiaen" <luc.misti...@advalvas.be.no.spam>
wrote:
add

errorMessage.Dispose()

in your Finally

/LM

"InnoCreate" <J...@InnoCreate.comwrote in message

news:11**********************@a75g2000cwd.googlegr oups.com...
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- Hide quoted text -

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

Feb 25 '07 #3
On 25 Feb, 04:33, "Luc E. Mistiaen" <luc.misti...@advalvas.be.no.spam>
wrote:
add

errorMessage.Dispose()

in your Finally

/LM

"InnoCreate" <J...@InnoCreate.comwrote in message

news:11**********************@a75g2000cwd.googlegr oups.com...
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- Hide quoted text -

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

Feb 25 '07 #4
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.

"InnoCreate" wrote:
On 25 Feb, 04:33, "Luc E. Mistiaen" <luc.misti...@advalvas.be.no.spam>
wrote:
add

errorMessage.Dispose()

in your Finally

/LM

"InnoCreate" <J...@InnoCreate.comwrote in message

news:11**********************@a75g2000cwd.googlegr oups.com...
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- Hide quoted text -
- Show quoted text -

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

Mar 16 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bryan Martin | last post by:
I have a program which has ran every night fine until last night. Now it bombs with the following errors. I have also broke this down to its simplest form for sending the mail...
1
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to...
2
by: ChrisA | last post by:
I'm sending email from my ASP.NET 1.1 app, and it works fine providing the BodyFormat of the System.Web.Mail.MailMessage is set to Text. If I change to Html format, it breaks. Here's the code: ...
1
by: maflatoun | last post by:
Hi everyone, I'm coverting some of our code here from the old way of send email in ..net 1.1 to the new .net 2.0. However, everyone I switch the code the new method there is a delay of 1-2...
5
by: Nathan Sokalski | last post by:
I am moving an application that involves sending email from 1.1 to 2.0. I am attempting to convert the email-sending code from System.Web.Mail to System.Net.Mail. I think I have most of this...
2
by: satnamsarai | last post by:
Using System.Net.Mail: Sometimes I get error 'failure sending mail. Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.' Not sure how...
2
by: Rob | last post by:
I've got the following skeleton in my HttpApplication (global.aspx) file: Public Sub New() MyBase.New() ApplicationTimer = New System.Timers.Timer ApplicationTimer.BeginInit()...
11
by: Ed Bitzer | last post by:
I have been able using the namespace System.Web.Mail and its method Smtp.mail.send to mail simple text messages to a small group within our 55 and older community. I need help expanding the...
5
by: Henry Stock | last post by:
I am trying to understand the following error: Any thing you can tell me about this is appreciated. Security Exception Description: The application attempted to perform an operation not allowed...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.