[RESOLVED] System.Web.Mail.MailMessage fails 1 in every 5 mails
From my application which is running on a win2003 server, I send mail using .System.Web.Mail.MailMessage:
Public Sub SendMail(ByVal FromText As String, _
ByVal sendToText As String, ByVal SubjectText As String, _
ByVal BodyText As String)
If sendToText.ToString.Trim.Length >= 0 And FromText.ToString.Trim.Length > 0 Then
myMessage = New MailMessage
System.Web.Mail.SmtpMail.SmtpServer = "xxx.com"
Try
With myMessage
.BodyFormat = MailFormat.Text
.Priority = MailPriority.Normal
.To = sendToText.ToString
.From = FromText.ToString
.Subject = SubjectText.ToString
.Body = BodyText.ToString
End With
System.Web.Mail.SmtpMail.Send(myMessage)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information)
End Try
Now what happens is, that there is an irregular CDO error message. The first time I run it, 4 messages are being sent and on number 5 I get a "Could not access CDO.message object" error. Then I send another 5 messages in a row, and number 3 would fail, or number 1. So no pattern at all.
Anyone seen that behaviour before?
Re: System.Web.Mail.MailMessage fails 1 in every 5 mails
Quote:
Originally Posted by PVR
From my application which is running on a win2003 server, I send mail using .System.Web.Mail.MailMessage:
Public Sub SendMail(ByVal FromText As String, _
ByVal sendToText As String, ByVal SubjectText As String, _
ByVal BodyText As String)
If sendToText.ToString.Trim.Length >= 0 And FromText.ToString.Trim.Length > 0 Then
myMessage = New MailMessage
System.Web.Mail.SmtpMail.SmtpServer = "xxx.com"
Try
With myMessage
.BodyFormat = MailFormat.Text
.Priority = MailPriority.Normal
.To = sendToText.ToString
.From = FromText.ToString
.Subject = SubjectText.ToString
.Body = BodyText.ToString
End With
System.Web.Mail.SmtpMail.Send(myMessage)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information)
End Try
Now what happens is, that there is an irregular CDO error message. The first time I run it, 4 messages are being sent and on number 5 I get a "Could not access CDO.message object" error. Then I send another 5 messages in a row, and number 3 would fail, or number 1. So no pattern at all.
Anyone seen that behaviour before?
could ur smtp server be blocking ur requests because ur trying to send to many at once?
Re: System.Web.Mail.MailMessage fails 1 in every 5 mails
For the sake of troubleshooting, add a small 3 second or 5 second timer to your loop and then try sending the emails out.
Re: System.Web.Mail.MailMessage fails 1 in every 5 mails
I just tried that, but no luck. On the second test, the mail even failed on the very first "send".
First test : have 30 seconds between the first and second mail : second mail failed
Second test: Failed on the first mail already
Is there a way of actually seeing what the SMTP server responded? I could not see a "proper" error in any of the debug values
Thanks for your help so far guys.
Re: System.Web.Mail.MailMessage fails 1 in every 5 mails
Ok - the way I solved it was as follows:
- I put a loop around the mailsend command which re-tries up to 5 times
Whenever it fails, it now will work on the second or third retry.
Thanks for your suggestions guys.