473,395 Members | 1,368 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,395 software developers and data experts.

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 sFromEmailAddress 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("smtp.realname.net") '

Dim MyEmail As New System.Net.Mail.MailMessage

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

Dim MyAddressTo As New System.Net.Mail.MailAddress(sToEmailAddress)

'Build the email

MyEmail.From = MyAddressFrom

MyEmail.To.Add(sToEmailAddress)

MyEmail.Subject = sEmailSubject

MyEmail.Body = sEmailBody

MyEmail.Priority = EmailPriority

MyEmail.IsBodyHtml = True

Dim MyMailObject As Object = MyEmail

AddHandler MySMTPClient.SendCompleted, AddressOf SmtpClient_OnCompleted

MySMTPClient.SendAsync(MyEmail, MyMailObject)

MyEmail = Nothing

'If there are any errors catch them

Catch MyException As Exception

MsgBox("The following error occured: " + MyException.Message,
MsgBoxStyle.Critical, "Sending email")

End Try

End Sub

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

Public Sub SmtpClient_OnCompleted(ByVal sender As Object, ByVal e As
System.ComponentModel.AsyncCompletedEventArgs)

'Get the Original MailMessage object

Dim mail As System.Net.Mail.MailMessage = CType(e.UserState,
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.OkCancel,
Application.ProductName)

End If

End Sub
May 6 '06 #1
6 2008
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*******@Webmaster2001.freeserve.co.uk> wrote in message
news:eA*************@TK2MSFTNGP04.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 sFromEmailAddress 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("smtp.realname.net") '

Dim MyEmail As New System.Net.Mail.MailMessage

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

Dim MyAddressTo As New System.Net.Mail.MailAddress(sToEmailAddress)

'Build the email

MyEmail.From = MyAddressFrom

MyEmail.To.Add(sToEmailAddress)

MyEmail.Subject = sEmailSubject

MyEmail.Body = sEmailBody

MyEmail.Priority = EmailPriority

MyEmail.IsBodyHtml = True

Dim MyMailObject As Object = MyEmail

AddHandler MySMTPClient.SendCompleted, AddressOf SmtpClient_OnCompleted

MySMTPClient.SendAsync(MyEmail, MyMailObject)

MyEmail = Nothing

'If there are any errors catch them

Catch MyException As Exception

MsgBox("The following error occured: " + MyException.Message,
MsgBoxStyle.Critical, "Sending email")

End Try

End Sub

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

Public Sub SmtpClient_OnCompleted(ByVal sender As Object, ByVal e As
System.ComponentModel.AsyncCompletedEventArgs)

'Get the Original MailMessage object

Dim mail As System.Net.Mail.MailMessage = CType(e.UserState,
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.OkCancel,
Application.ProductName)

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*******@Webmaster2001.freeserve.co.uk> wrote in message
news:%2****************@TK2MSFTNGP04.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*******@Webmaster2001.freeserve.co.uk> wrote in message
news:eA*************@TK2MSFTNGP04.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 sFromEmailAddress 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("smtp.realname.net") '

Dim MyEmail As New System.Net.Mail.MailMessage

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

Dim MyAddressTo As New System.Net.Mail.MailAddress(sToEmailAddress)

'Build the email

MyEmail.From = MyAddressFrom

MyEmail.To.Add(sToEmailAddress)

MyEmail.Subject = sEmailSubject

MyEmail.Body = sEmailBody

MyEmail.Priority = EmailPriority

MyEmail.IsBodyHtml = True

Dim MyMailObject As Object = MyEmail

AddHandler MySMTPClient.SendCompleted, AddressOf SmtpClient_OnCompleted

MySMTPClient.SendAsync(MyEmail, MyMailObject)

MyEmail = Nothing

'If there are any errors catch them

Catch MyException As Exception

MsgBox("The following error occured: " + MyException.Message,
MsgBoxStyle.Critical, "Sending email")

End Try

End Sub

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

Public Sub SmtpClient_OnCompleted(ByVal sender As Object, ByVal e As
System.ComponentModel.AsyncCompletedEventArgs)

'Get the Original MailMessage object

Dim mail As System.Net.Mail.MailMessage = CType(e.UserState,
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.OkCancel,
Application.ProductName)

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*******@Webmaster2001.freeserve.co.uk> wrote in message
news:eA*************@TK2MSFTNGP04.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 sFromEmailAddress 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("smtp.realname.net") '

Dim MyEmail As New System.Net.Mail.MailMessage

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

Dim MyAddressTo As New System.Net.Mail.MailAddress(sToEmailAddress)

'Build the email

MyEmail.From = MyAddressFrom

MyEmail.To.Add(sToEmailAddress)

MyEmail.Subject = sEmailSubject

MyEmail.Body = sEmailBody

MyEmail.Priority = EmailPriority

MyEmail.IsBodyHtml = True

Dim MyMailObject As Object = MyEmail

AddHandler MySMTPClient.SendCompleted, AddressOf SmtpClient_OnCompleted

MySMTPClient.SendAsync(MyEmail, MyMailObject)

MyEmail = Nothing

'If there are any errors catch them

Catch MyException As Exception

MsgBox("The following error occured: " + MyException.Message,
MsgBoxStyle.Critical, "Sending email")

End Try

End Sub

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

Public Sub SmtpClient_OnCompleted(ByVal sender As Object, ByVal e As
System.ComponentModel.AsyncCompletedEventArgs)

'Get the Original MailMessage object

Dim mail As System.Net.Mail.MailMessage = CType(e.UserState,
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.OkCancel,
Application.ProductName)

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*******@hotmail.com> wrote in message
news:OH**************@TK2MSFTNGP05.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*******@Webmaster2001.freeserve.co.uk> wrote in message
news:eA*************@TK2MSFTNGP04.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 sFromEmailAddress 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("smtp.realname.net") '

Dim MyEmail As New System.Net.Mail.MailMessage

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

Dim MyAddressTo As New System.Net.Mail.MailAddress(sToEmailAddress)

'Build the email

MyEmail.From = MyAddressFrom

MyEmail.To.Add(sToEmailAddress)

MyEmail.Subject = sEmailSubject

MyEmail.Body = sEmailBody

MyEmail.Priority = EmailPriority

MyEmail.IsBodyHtml = True

Dim MyMailObject As Object = MyEmail

AddHandler MySMTPClient.SendCompleted, AddressOf SmtpClient_OnCompleted

MySMTPClient.SendAsync(MyEmail, MyMailObject)

MyEmail = Nothing

'If there are any errors catch them

Catch MyException As Exception

MsgBox("The following error occured: " + MyException.Message,
MsgBoxStyle.Critical, "Sending email")

End Try

End Sub

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

Public Sub SmtpClient_OnCompleted(ByVal sender As Object, ByVal e As
System.ComponentModel.AsyncCompletedEventArgs)

'Get the Original MailMessage object

Dim mail As System.Net.Mail.MailMessage = CType(e.UserState,
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.OkCancel,
Application.ProductName)

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*******@Webmaster2001.freeserve.co.uk> wrote in message
news:%2****************@TK2MSFTNGP04.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*******@Webmaster2001.freeserve.co.uk> wrote in message
news:eA*************@TK2MSFTNGP04.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 sFromEmailAddress 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("smtp.realname.net") '

Dim MyEmail As New System.Net.Mail.MailMessage

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

Dim MyAddressTo As New System.Net.Mail.MailAddress(sToEmailAddress)

'Build the email

MyEmail.From = MyAddressFrom

MyEmail.To.Add(sToEmailAddress)

MyEmail.Subject = sEmailSubject

MyEmail.Body = sEmailBody

MyEmail.Priority = EmailPriority

MyEmail.IsBodyHtml = True

Dim MyMailObject As Object = MyEmail

AddHandler MySMTPClient.SendCompleted, AddressOf SmtpClient_OnCompleted

MySMTPClient.SendAsync(MyEmail, MyMailObject)

MyEmail = Nothing

'If there are any errors catch them

Catch MyException As Exception

MsgBox("The following error occured: " + MyException.Message,
MsgBoxStyle.Critical, "Sending email")

End Try

End Sub

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

Public Sub SmtpClient_OnCompleted(ByVal sender As Object, ByVal e As
System.ComponentModel.AsyncCompletedEventArgs)

'Get the Original MailMessage object

Dim mail As System.Net.Mail.MailMessage = CType(e.UserState,
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.OkCancel,
Application.ProductName)

End If

End Sub


May 12 '06 #6
Liz

"+Vice" <to******@earthlink.net> wrote in message
news:uZ**************@TK2MSFTNGP04.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
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. ...
34
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...
9
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...
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: 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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.