ASP Mail CDOSYS Object Problem

Nathan

Perch
I am using a CDOSYS object to send emails via a script (for forum post notifications). All works fine, but occasionally I get the following error:

CDO.Message.1 error '80040213'

The transport failed to connect to the server.

/send_mail.asp, line 141



Is there a way to catch the error, using on resume next? If so, how do I do this so that I get an error code but not to stop the script. (Function for sending the mail shown below.)

Thanks for any help you can offer,

Nathan





With objCDOSYSMail
'Who the e-mail is from
.From = """" & theWebsiteName & """ <" & theWebsiteEmailAddress & ">"""

'Who the e-mail is sent to
.To = """" & strToName & """ <" & strEmailAddress & ">"""

'The subject of the e-mail
.Subject = theSubject

'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)
If strMailFormat = "HTML" Then
.HTMLBody = theEmailBody & strAppendToEmail
Else
.TextBody = theEmailBody & strAppendToEmail
End If

'Send the e-mail
If NOT strMailServer = "" Then .Send
End with


PS I'm closing the oject each time.
 
This will keep the script from stopping:
On Error resume next

This will see if there was an error:
if err.number=0 then
'Ok
else
'an error was detected,
'handle it.

Also note that there is a
Server.GetLastError()
method that will return an ASPError object.

Hope that helps.
riley
 
basically this error happens when the mail server is unreachable or terminating the connection early, there was an issue on the server you were on today due to a spammer, and we cleaned that up it should be resolved now.
 
Riley, thanks for that.

It works perfectly now. I am also catching any errors and recording them - so I can check if the email address, being incorrectly formed, is the problem.

Thanks again.

Nathan
 
I'm glad it worked for you.

By the way, I forgot to mention that to have the ASP interpreter return to monitoring errors you use the following:
On Error GoTo 0

Also, I cannot remember the scope of the On Error Resume Next statement. It might be limited to the sub or function in which it is used, but given that ASP is very "global" by nature, I suspect that the scope of the statement is application-wide. That is to say, once you use it, the ASP interpreter is no longer monitoring errors, even after exiting the sub of function in which you used the statement.

riley
 
Back
Top