Link to home
Start Free TrialLog in
Avatar of Alfahane
Alfahane

asked on

Managing incorrect email address in CDO

How do I manage the error produced by CDO (in classic ASP/VBScript) when a receiver email address is incorrect?

Right now if the email address is incorrect and 8004020e is produced. I understand why the problem occurs but I don't know how to handle it. This function is used to send out quite a lot of emails so I want to avoid

The best thing (I think) would be to if CDO could return some kind of indication that the address is incorrect without causing the entire script to fail. However, suggestions are more than welcome.
function(smtp,toEmail,fromEmail,emailHeader,emailBody)
	dim Mailer, cdoConfig
	Set Mailer = Server.CreateObject("CDO.Message")
	set cdoConfig = Server.CreateObject("CDO.Configuration")
	cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
	cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtp
	cdoConfig.Fields.Update
	set Mailer.Configuration = cdoConfig
	Mailer.To = toEmail
	Mailer.From = fromEmail
	Mailer.Subject = emailHeader
	Mailer.TextBody = emailBody
	Mailer.Send
	if err.number>0 then
	   sendemail=false
	else
	   sendemail=true
	end if
	Set Mailer = Nothing
	Set cdoConfig = Nothing
end function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dxpert
Dxpert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh yeah.. Err.Clear :-D


if err.number <> 0 then
                sendemail=toEmail
                Err.Clear
else
                sendemail=""
end if
Avatar of Alfahane
Alfahane

ASKER

Great! Thanks!! =)
Just realized:

This means that all errors will be supposed to be a problem with email validity.

I remember there's one error that has to be with the size of the email.

Is there no way that confirm that the error is in fact an email validity issue?

I guess if you figure out what the error number is, then you can use that. For instance, if that error number would be 55555555 then you could do something like this:



if err.number <> 0 then
      if err.number <> 55555555 then
            sendemail=toEmail
            Err.Clear
      end if
else
      sendemail=""
end if
to figure out what that error is, you can, send a very long email, then use this IF statement instead:


if err.number <> 0 then
      response.write("Error Number: " & err.number & "<br />")
      response.write("Error Description: " & err.description & "<br />")
      response.end
end if