Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cdos

Status
Not open for further replies.

aspnet98

MIS
May 19, 2005
165
0
0
US
I am using the following cdos code to connect to a remote smtp mail server. it works perfectly when a valid email address is given, if a fake one is given then it errors the page. is their anyway to prevent this? i tried the javascript approach but it still fails sometimes.

Const cdoSendUsingMethod = _
"Const cdoSendUsingPort = 2
Const cdoSMTPServer = _
"Const cdoSMTPServerPort = _
"Const cdoSMTPConnectionTimeout = _
"Const cdoSMTPAuthenticate = _
"Const cdoBasic = 1
Const cdoSendUserName = _
"Const cdoSendPassword = _
"
Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields

' Get a handle on the config object and it's fields
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields

' Set config fields we care about
With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = ""
.Item(cdoSMTPServerPort) = 587
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "administrator@efbp.net"
.Item(cdoSendPassword) = ""

.Update
End With

Set objMessage = Server.CreateObject("CDO.Message")

Set objMessage.Configuration = objConfig

With objMessage
.To = strTo
.Bcc = "<>"
.From = "<>"
.Subject = ""
.TextBody = strMailBody
.Send
End With

Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
 
Just control the most probable lines where the actions might fail, say for instance surrounding .send.
[tt]
on error resume next
With objMessage
.To = strTo
.Bcc = "<>"
.From = "<>"
.Subject = ""
.TextBody = strMailBody
.Send
End With
if err.number<>0 then
'do something for instance to keep an error log
err.clear
end if
on error goto 0
[/tt]
 
That worked! I am not sure I understand the error log part? how to I write to a error log the message?
 
>I am not sure I understand the error log part?

That could be as simple as documenting the mishappening by writing the main data and date-time involved to a simple text file at the server. It really depends on your need.

If you do not find it a pressing issue, you could simple ignore the "if err.number<>0 then ... end if" block. Err object would automatically be cleared on the statementwhen encountering the statement "on error goto 0". And the script will continue no problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top