Click to See Complete Forum and Search --> : Exception handling with CDO.message


4dam
11-17-2005, 04:38 AM
Hi,

I am using code based on the following to send an email from a form on my site. One to me, and a confrmation email to the customer.

<%
theSchema="http://schemas.microsoft.com/cdo/configuration"
set cdoConfig=server.CreateObject("CDO.configuration")
cdoConfig.fields.item(theSchema & "sendusing")=2
cdoConfig.fields.item(theSchema & "smtpserver")="my.smtp.server"
cdoConfig.fields.update

set cdoMessage=server.createObject("cdo.message")
cdoMessage.configuration=cdoConfig
cdoMessage.from=request.form("email")
cdoMessage.to=request.form("to")
cdoMessage.subject=request.form("subject")
cdoMessage.textbody=request.form("message")
cdoMessage.send

set cdoConfig=nothing
set cdoMessage=nothing

%>


The problem is, that if the customer enters an incorrect email address, the site displays an error message.

I have an error page set up, informing the customer that their message couldn't be sent, and directing them back to check their email address, but how do I get it to divert to this page, rather than throwing an unhelpful error message?

Any help would be gratefully appreciated.

Thanks,

Adam

Giskard
11-17-2005, 12:46 PM
Before the cdoMessage.send line add the following:
On Error Resume Next
then after the cdoMessage.send line add the following:
If Err.Number <> 0 Then
Response.Redirect("ErrorPage.asp")
end if


You may want to check the error number to be sure that the e-mail address was the problem.

4dam
11-19-2005, 07:26 AM
Thanks