473,692 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SMTP won't send until thread terminates

Okay.

This is a little strange but here goes.

I wanted to send emails and hence wrote the first sub below. It worked
however it would NOT send the email UNLESS I closed the application (hence
terminated the main thread).

Wanting to fix this I thought it would work if I do it the asyncrhonous way
so the calling thread isn't blocked. This is when I added the 2nd sub below

All the code still works but again, it does not send the email unless I exit
the application. It's almost as if its buffering it for some reason.

Shouldn't this just get fired ASAP as soon as I do .sendasync() or .send()
?????

Very confusing.

Thanks for all feedback,
Adam

************SUB 1************** **
Public Sub SendEmail(ByVal sFromEmailAddre ss As String, ByVal
sFromSenderName As String, ByVal sToEmailAddress As String, ByVal
sEmailSubject As String, ByVal sEmailBody As String, ByVal EmailPriority As
System.Net.Mail .MailPriority)

Try

Dim MySMTPClient As New System.Net.Mail .SmtpClient("sm tp.realname.net ") '

Dim MyEmail As New System.Net.Mail .MailMessage

Dim MyAddressFrom As New System.Net.Mail .MailAddress(sF romEmailAddress ,
sFromSenderName )

Dim MyAddressTo As New System.Net.Mail .MailAddress(sT oEmailAddress)

'Build the email

MyEmail.From = MyAddressFrom

MyEmail.To.Add( sToEmailAddress )

MyEmail.Subject = sEmailSubject

MyEmail.Body = sEmailBody

MyEmail.Priorit y = EmailPriority

MyEmail.IsBodyH tml = True

Dim MyMailObject As Object = MyEmail

AddHandler MySMTPClient.Se ndCompleted, AddressOf SmtpClient_OnCo mpleted

MySMTPClient.Se ndAsync(MyEmail , MyMailObject)

MyEmail = Nothing

'If there are any errors catch them

Catch MyException As Exception

MsgBox("The following error occured: " + MyException.Mes sage,
MsgBoxStyle.Cri tical, "Sending email")

End Try

End Sub

************SUB 2************** **

Public Sub SmtpClient_OnCo mpleted(ByVal sender As Object, ByVal e As
System.Componen tModel.AsyncCom pletedEventArgs )

'Get the Original MailMessage object

Dim mail As System.Net.Mail .MailMessage = CType(e.UserSta te,
System.Net.Mail .MailMessage)

'write out the subject

Dim subject As String = mail.Subject

If e.Cancelled Then

'They cancelled it last minute

End If

If Not (e.Error Is Nothing) Then

'Explain to the user

Else

MsgBox("The email has been sent", MsgBoxStyle.OkC ancel,
Application.Pro ductName)

End If

End Sub
May 6 '06 #1
6 2028
Just to add to what I already said.

I put it all in a class module to let it run in its own thread.

The same thing happens. Ie it won't send the email until I terminate the
application.

There are no errors, it's buffering it somewhere but I'm just so confused
where and how. I haven't setup any buffering, it should send ASAP.

Adam

"Adam Honek" <Ad*******@Webm aster2001.frees erve.co.uk> wrote in message
news:eA******** *****@TK2MSFTNG P04.phx.gbl...
Okay.

This is a little strange but here goes.

I wanted to send emails and hence wrote the first sub below. It worked
however it would NOT send the email UNLESS I closed the application (hence
terminated the main thread).

Wanting to fix this I thought it would work if I do it the asyncrhonous
way so the calling thread isn't blocked. This is when I added the 2nd sub
below

All the code still works but again, it does not send the email unless I
exit the application. It's almost as if its buffering it for some reason.

Shouldn't this just get fired ASAP as soon as I do .sendasync() or .send()
?????

Very confusing.

Thanks for all feedback,
Adam

************SUB 1************** **
Public Sub SendEmail(ByVal sFromEmailAddre ss As String, ByVal
sFromSenderName As String, ByVal sToEmailAddress As String, ByVal
sEmailSubject As String, ByVal sEmailBody As String, ByVal EmailPriority
As System.Net.Mail .MailPriority)

Try

Dim MySMTPClient As New System.Net.Mail .SmtpClient("sm tp.realname.net ") '

Dim MyEmail As New System.Net.Mail .MailMessage

Dim MyAddressFrom As New System.Net.Mail .MailAddress(sF romEmailAddress ,
sFromSenderName )

Dim MyAddressTo As New System.Net.Mail .MailAddress(sT oEmailAddress)

'Build the email

MyEmail.From = MyAddressFrom

MyEmail.To.Add( sToEmailAddress )

MyEmail.Subject = sEmailSubject

MyEmail.Body = sEmailBody

MyEmail.Priorit y = EmailPriority

MyEmail.IsBodyH tml = True

Dim MyMailObject As Object = MyEmail

AddHandler MySMTPClient.Se ndCompleted, AddressOf SmtpClient_OnCo mpleted

MySMTPClient.Se ndAsync(MyEmail , MyMailObject)

MyEmail = Nothing

'If there are any errors catch them

Catch MyException As Exception

MsgBox("The following error occured: " + MyException.Mes sage,
MsgBoxStyle.Cri tical, "Sending email")

End Try

End Sub

************SUB 2************** **

Public Sub SmtpClient_OnCo mpleted(ByVal sender As Object, ByVal e As
System.Componen tModel.AsyncCom pletedEventArgs )

'Get the Original MailMessage object

Dim mail As System.Net.Mail .MailMessage = CType(e.UserSta te,
System.Net.Mail .MailMessage)

'write out the subject

Dim subject As String = mail.Subject

If e.Cancelled Then

'They cancelled it last minute

End If

If Not (e.Error Is Nothing) Then

'Explain to the user

Else

MsgBox("The email has been sent", MsgBoxStyle.OkC ancel,
Application.Pro ductName)

End If

End Sub

May 6 '06 #2
Further to the above.

Sometimes it will send immediately.

Sometimes it won't until I exit the app.

Obviously something somewhere isn't get priority. The UI in the main thread
blocking the SMTP System.net.mail classes? Doubtful but that's all I can
think up.

Adam

"Adam Honek" <Ad*******@Webm aster2001.frees erve.co.uk> wrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Just to add to what I already said.

I put it all in a class module to let it run in its own thread.

The same thing happens. Ie it won't send the email until I terminate the
application.

There are no errors, it's buffering it somewhere but I'm just so confused
where and how. I haven't setup any buffering, it should send ASAP.

Adam

"Adam Honek" <Ad*******@Webm aster2001.frees erve.co.uk> wrote in message
news:eA******** *****@TK2MSFTNG P04.phx.gbl...
Okay.

This is a little strange but here goes.

I wanted to send emails and hence wrote the first sub below. It worked
however it would NOT send the email UNLESS I closed the application
(hence terminated the main thread).

Wanting to fix this I thought it would work if I do it the asyncrhonous
way so the calling thread isn't blocked. This is when I added the 2nd sub
below

All the code still works but again, it does not send the email unless I
exit the application. It's almost as if its buffering it for some reason.

Shouldn't this just get fired ASAP as soon as I do .sendasync() or
.send() ?????

Very confusing.

Thanks for all feedback,
Adam

************SUB 1************** **
Public Sub SendEmail(ByVal sFromEmailAddre ss As String, ByVal
sFromSenderName As String, ByVal sToEmailAddress As String, ByVal
sEmailSubject As String, ByVal sEmailBody As String, ByVal EmailPriority
As System.Net.Mail .MailPriority)

Try

Dim MySMTPClient As New System.Net.Mail .SmtpClient("sm tp.realname.net ") '

Dim MyEmail As New System.Net.Mail .MailMessage

Dim MyAddressFrom As New System.Net.Mail .MailAddress(sF romEmailAddress ,
sFromSenderName )

Dim MyAddressTo As New System.Net.Mail .MailAddress(sT oEmailAddress)

'Build the email

MyEmail.From = MyAddressFrom

MyEmail.To.Add( sToEmailAddress )

MyEmail.Subject = sEmailSubject

MyEmail.Body = sEmailBody

MyEmail.Priorit y = EmailPriority

MyEmail.IsBodyH tml = True

Dim MyMailObject As Object = MyEmail

AddHandler MySMTPClient.Se ndCompleted, AddressOf SmtpClient_OnCo mpleted

MySMTPClient.Se ndAsync(MyEmail , MyMailObject)

MyEmail = Nothing

'If there are any errors catch them

Catch MyException As Exception

MsgBox("The following error occured: " + MyException.Mes sage,
MsgBoxStyle.Cri tical, "Sending email")

End Try

End Sub

************SUB 2************** **

Public Sub SmtpClient_OnCo mpleted(ByVal sender As Object, ByVal e As
System.Componen tModel.AsyncCom pletedEventArgs )

'Get the Original MailMessage object

Dim mail As System.Net.Mail .MailMessage = CType(e.UserSta te,
System.Net.Mail .MailMessage)

'write out the subject

Dim subject As String = mail.Subject

If e.Cancelled Then

'They cancelled it last minute

End If

If Not (e.Error Is Nothing) Then

'Explain to the user

Else

MsgBox("The email has been sent", MsgBoxStyle.OkC ancel,
Application.Pro ductName)

End If

End Sub


May 7 '06 #3
Dear Adam Honek

I have encountered the same situation.

I have noticed that my Email Virus Autoprotect is doing this. If I turn the
Autoprotect feature off, I have no problem in sending emails.

Mike TI

"Adam Honek" <Ad*******@Webm aster2001.frees erve.co.uk> wrote in message
news:eA******** *****@TK2MSFTNG P04.phx.gbl...
Okay.

This is a little strange but here goes.

I wanted to send emails and hence wrote the first sub below. It worked
however it would NOT send the email UNLESS I closed the application (hence
terminated the main thread).

Wanting to fix this I thought it would work if I do it the asyncrhonous
way so the calling thread isn't blocked. This is when I added the 2nd sub
below

All the code still works but again, it does not send the email unless I
exit the application. It's almost as if its buffering it for some reason.

Shouldn't this just get fired ASAP as soon as I do .sendasync() or .send()
?????

Very confusing.

Thanks for all feedback,
Adam

************SUB 1************** **
Public Sub SendEmail(ByVal sFromEmailAddre ss As String, ByVal
sFromSenderName As String, ByVal sToEmailAddress As String, ByVal
sEmailSubject As String, ByVal sEmailBody As String, ByVal EmailPriority
As System.Net.Mail .MailPriority)

Try

Dim MySMTPClient As New System.Net.Mail .SmtpClient("sm tp.realname.net ") '

Dim MyEmail As New System.Net.Mail .MailMessage

Dim MyAddressFrom As New System.Net.Mail .MailAddress(sF romEmailAddress ,
sFromSenderName )

Dim MyAddressTo As New System.Net.Mail .MailAddress(sT oEmailAddress)

'Build the email

MyEmail.From = MyAddressFrom

MyEmail.To.Add( sToEmailAddress )

MyEmail.Subject = sEmailSubject

MyEmail.Body = sEmailBody

MyEmail.Priorit y = EmailPriority

MyEmail.IsBodyH tml = True

Dim MyMailObject As Object = MyEmail

AddHandler MySMTPClient.Se ndCompleted, AddressOf SmtpClient_OnCo mpleted

MySMTPClient.Se ndAsync(MyEmail , MyMailObject)

MyEmail = Nothing

'If there are any errors catch them

Catch MyException As Exception

MsgBox("The following error occured: " + MyException.Mes sage,
MsgBoxStyle.Cri tical, "Sending email")

End Try

End Sub

************SUB 2************** **

Public Sub SmtpClient_OnCo mpleted(ByVal sender As Object, ByVal e As
System.Componen tModel.AsyncCom pletedEventArgs )

'Get the Original MailMessage object

Dim mail As System.Net.Mail .MailMessage = CType(e.UserSta te,
System.Net.Mail .MailMessage)

'write out the subject

Dim subject As String = mail.Subject

If e.Cancelled Then

'They cancelled it last minute

End If

If Not (e.Error Is Nothing) Then

'Explain to the user

Else

MsgBox("The email has been sent", MsgBoxStyle.OkC ancel,
Application.Pro ductName)

End If

End Sub

May 7 '06 #4
Hmmm,

Norton Antivirus?

I have version 2006 and it's not wanting to turn off, just disable. If I
disable it the emails
send ASAP on a 50/50 basis, depending what they feel like doing.

:(

Adam

"Mike TI" <su*******@hotm ail.com> wrote in message
news:OH******** ******@TK2MSFTN GP05.phx.gbl...
Dear Adam Honek

I have encountered the same situation.

I have noticed that my Email Virus Autoprotect is doing this. If I turn
the Autoprotect feature off, I have no problem in sending emails.

Mike TI

"Adam Honek" <Ad*******@Webm aster2001.frees erve.co.uk> wrote in message
news:eA******** *****@TK2MSFTNG P04.phx.gbl...
Okay.

This is a little strange but here goes.

I wanted to send emails and hence wrote the first sub below. It worked
however it would NOT send the email UNLESS I closed the application
(hence terminated the main thread).

Wanting to fix this I thought it would work if I do it the asyncrhonous
way so the calling thread isn't blocked. This is when I added the 2nd sub
below

All the code still works but again, it does not send the email unless I
exit the application. It's almost as if its buffering it for some reason.

Shouldn't this just get fired ASAP as soon as I do .sendasync() or
.send() ?????

Very confusing.

Thanks for all feedback,
Adam

************SUB 1************** **
Public Sub SendEmail(ByVal sFromEmailAddre ss As String, ByVal
sFromSenderName As String, ByVal sToEmailAddress As String, ByVal
sEmailSubject As String, ByVal sEmailBody As String, ByVal EmailPriority
As System.Net.Mail .MailPriority)

Try

Dim MySMTPClient As New System.Net.Mail .SmtpClient("sm tp.realname.net ") '

Dim MyEmail As New System.Net.Mail .MailMessage

Dim MyAddressFrom As New System.Net.Mail .MailAddress(sF romEmailAddress ,
sFromSenderName )

Dim MyAddressTo As New System.Net.Mail .MailAddress(sT oEmailAddress)

'Build the email

MyEmail.From = MyAddressFrom

MyEmail.To.Add( sToEmailAddress )

MyEmail.Subject = sEmailSubject

MyEmail.Body = sEmailBody

MyEmail.Priorit y = EmailPriority

MyEmail.IsBodyH tml = True

Dim MyMailObject As Object = MyEmail

AddHandler MySMTPClient.Se ndCompleted, AddressOf SmtpClient_OnCo mpleted

MySMTPClient.Se ndAsync(MyEmail , MyMailObject)

MyEmail = Nothing

'If there are any errors catch them

Catch MyException As Exception

MsgBox("The following error occured: " + MyException.Mes sage,
MsgBoxStyle.Cri tical, "Sending email")

End Try

End Sub

************SUB 2************** **

Public Sub SmtpClient_OnCo mpleted(ByVal sender As Object, ByVal e As
System.Componen tModel.AsyncCom pletedEventArgs )

'Get the Original MailMessage object

Dim mail As System.Net.Mail .MailMessage = CType(e.UserSta te,
System.Net.Mail .MailMessage)

'write out the subject

Dim subject As String = mail.Subject

If e.Cancelled Then

'They cancelled it last minute

End If

If Not (e.Error Is Nothing) Then

'Explain to the user

Else

MsgBox("The email has been sent", MsgBoxStyle.OkC ancel,
Application.Pro ductName)

End If

End Sub


May 7 '06 #5
Ever find a solution to this? Appears to be related to some type of
anti-virus protection. I'm getting the same thing but am working to find a
workaround. Mine is due to the Norton auto-protection.

"Adam Honek" <Ad*******@Webm aster2001.frees erve.co.uk> wrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Just to add to what I already said.

I put it all in a class module to let it run in its own thread.

The same thing happens. Ie it won't send the email until I terminate the
application.

There are no errors, it's buffering it somewhere but I'm just so confused
where and how. I haven't setup any buffering, it should send ASAP.

Adam

"Adam Honek" <Ad*******@Webm aster2001.frees erve.co.uk> wrote in message
news:eA******** *****@TK2MSFTNG P04.phx.gbl...
Okay.

This is a little strange but here goes.

I wanted to send emails and hence wrote the first sub below. It worked
however it would NOT send the email UNLESS I closed the application
(hence terminated the main thread).

Wanting to fix this I thought it would work if I do it the asyncrhonous
way so the calling thread isn't blocked. This is when I added the 2nd sub
below

All the code still works but again, it does not send the email unless I
exit the application. It's almost as if its buffering it for some reason.

Shouldn't this just get fired ASAP as soon as I do .sendasync() or
.send() ?????

Very confusing.

Thanks for all feedback,
Adam

************SUB 1************** **
Public Sub SendEmail(ByVal sFromEmailAddre ss As String, ByVal
sFromSenderName As String, ByVal sToEmailAddress As String, ByVal
sEmailSubject As String, ByVal sEmailBody As String, ByVal EmailPriority
As System.Net.Mail .MailPriority)

Try

Dim MySMTPClient As New System.Net.Mail .SmtpClient("sm tp.realname.net ") '

Dim MyEmail As New System.Net.Mail .MailMessage

Dim MyAddressFrom As New System.Net.Mail .MailAddress(sF romEmailAddress ,
sFromSenderName )

Dim MyAddressTo As New System.Net.Mail .MailAddress(sT oEmailAddress)

'Build the email

MyEmail.From = MyAddressFrom

MyEmail.To.Add( sToEmailAddress )

MyEmail.Subject = sEmailSubject

MyEmail.Body = sEmailBody

MyEmail.Priorit y = EmailPriority

MyEmail.IsBodyH tml = True

Dim MyMailObject As Object = MyEmail

AddHandler MySMTPClient.Se ndCompleted, AddressOf SmtpClient_OnCo mpleted

MySMTPClient.Se ndAsync(MyEmail , MyMailObject)

MyEmail = Nothing

'If there are any errors catch them

Catch MyException As Exception

MsgBox("The following error occured: " + MyException.Mes sage,
MsgBoxStyle.Cri tical, "Sending email")

End Try

End Sub

************SUB 2************** **

Public Sub SmtpClient_OnCo mpleted(ByVal sender As Object, ByVal e As
System.Componen tModel.AsyncCom pletedEventArgs )

'Get the Original MailMessage object

Dim mail As System.Net.Mail .MailMessage = CType(e.UserSta te,
System.Net.Mail .MailMessage)

'write out the subject

Dim subject As String = mail.Subject

If e.Cancelled Then

'They cancelled it last minute

End If

If Not (e.Error Is Nothing) Then

'Explain to the user

Else

MsgBox("The email has been sent", MsgBoxStyle.OkC ancel,
Application.Pro ductName)

End If

End Sub


May 12 '06 #6
Liz

"+Vice" <to******@earth link.net> wrote in message
news:uZ******** ******@TK2MSFTN GP04.phx.gbl...
Ever find a solution to this? Appears to be related to some type of
anti-virus protection. I'm getting the same thing but am working to find
a workaround. Mine is due to the Norton auto-protection.


I turned off outbound email scanning in Norton and it still scans anyway; I
do not have to exit the app for a send to be completed but it is deferred
for a minute or two
May 12 '06 #7

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

Similar topics

2
2556
by: Peter | last post by:
I am trying to send SMTP mail: I have the following code which works fine on one domain, but not on other. It does not work until I remove the Message-ID: line, than it works just fine. Here's how I removed the Message-ID line: I stopped the SMTP service (so I could edit the mail file in the Pickup directory), ran the program to send the email, than I edited the file in the Pickup directory and removed the Message-ID line from the...
34
18240
by: antonyliu2002 | last post by:
I've set up the virtual smtp server on my IIS 5.1 like so: 1. Assign IP address to "All Unassigned", and listen to port 25. 2. Access Connection granted to "127.0.0.1". 3. Relay only allow "127.0.0.1". 4. Authentication: "Anonymous access" only. 5. Outbound connection listen to TCP 25. Besides,
9
1275
by: Keith G Hicks | last post by:
I have a vb app that runs on a server. It periodically checks for rows in a table that are ready to have data mailed out to clients. After it finds row(s) that are ready, it emails the info out and then marks the rows as having been sent. It all works fine except for one thing. There have been a couple of times when the 2nd part chokes due to a conflict on the server. The mail is sent out but it never gets around to marking the rows as...
0
8603
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8537
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8955
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8796
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8800
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5818
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4556
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2236
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.