Send email using CDOSYS

I can't seem to make this work and I am not sure what I am doing wrong.

Dim iMsg
Set iMsg = CreateObject("CDO.Message")
Dim iBp
Dim Flds

Dim iConf
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
Flds(cdoSendUsingMethod)  = cdoSendUsingPort
Flds(cdoSMTPServer)       = ""
Flds(cdoSMTPServerPort)   = 25
Flds(cdoSMTPAuthenticate)     = cdoAnonymous ' 0

With iMsg
  Set .Configuration = iConf
    .To          = ""
    .From        = ""
    .Sender      = ""
    .Subject     = "Partner information change request"
    .TextBody    = "This is a test.<br>This is still a test." + vbLfCr + vbLfCr

End With

The code is from Microsofts site.

I am getting this error:
     ADODB.Fields error '800a0bb9'
     Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
     /test.asp, line 36

Line 36 is: Flds(cdoSendUsingMethod)  = cdoSendUsingPort
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saqib KhanSenior DeveloperCommented:
> Set iMsg = CreateObject("CDO.Message")

maybe try

Set iMsg = Server.CreateObject("CDO.Message")
lpenrodAuthor Commented:
No change.
lpenrodAuthor Commented:
Not sure if it is relevant.  The box is a Windows 2003 server running IIS6.
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.


It could be that the vb constants you're using aren't in the local scope.  Try adding these two lines to the very top of your file, if they're not already there:

<!--METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" NAME="CDO for Windows 2000 Library" -->
<!--METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4" NAME="ADODB Type Library" -->

Note that these go _outside_ of your server-side code <% %>.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lpenrodAuthor Commented:
That did it.

The points are yours, thanks!

For bonus points, do you know how to make it so I can send HTML code in the body?
You should be able to just set iMsg.HTMLBody to a string containing your HTML, like this:

With iMsg
  Set .Configuration = iConf
    .To          = ""
    .From        = ""
    .Sender      = ""
    .Subject     = "Partner information change request"
    .TextBody    = "This is the text body."
    .HTMLBody = "<html><body><p>This is the HTML Body.</p></body></html>"
End With

- make sure you always include a text body as some mailreaders won't display html, and some users don't want it.

- make sure HTMLBody is a well-formed html document, not just a string with html formatting (see example.)
lpenrodAuthor Commented:
You rock!
Saqib KhanSenior DeveloperCommented:
barryfandango so we can use this method to send email VIA win XP as well?
by adding the Library?
Yes, xp (pro) supports CDOSYS.  I think it even has it installed by default, but don't quote me on that.  So if your IIS is running on XP this should work (it works on my end.)
lpenrodAuthor Commented:
I have a question also if you know regarding the line:  Flds(cdoSMTPAuthenticate)     = cdoAnonymous ' 0

To prevent relaying, you have to be authenticated or on our internal private network.  Does this mean that if someone tried this from home it would fail since they are not on the internal private network?
That depends what you mean.  If your web-user was based from home, the server-side code is still running on your internal network (your IIS machine is doing the job.)  If the home user had IIS and was trying to execute this script then you could possibly encounter that problem.
lpenrodAuthor Commented:
Got you.  I forgot that the IIS server running the code is internal and therefore would be allowed to send mail.

Thanks again!
the script workws fine for me, as long as i use the email address that lives on the server.. i have a form that sends an emial to the address you enter into the form, . if for example the site is, the asp page will send an email to, but not for

i know it is something wrong with the STMP server, right?
lpenrodAuthor Commented:
Relay restriction?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.