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)       = "smtp.beap.com"
Flds(cdoSMTPServerPort)   = 25
Flds(cdoSMTPAuthenticate)     = cdoAnonymous ' 0
Flds.Update

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

    .Send
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
LVL 3
lpenrodAsked:
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")
0
lpenrodAuthor Commented:
No change.
0
lpenrodAuthor Commented:
Not sure if it is relevant.  The box is a Windows 2003 server running IIS6.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

barryfandangoCommented:
adilkhan,

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 <% %>.
0

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?
0
barryfandangoCommented:
You should be able to just set iMsg.HTMLBody to a string containing your HTML, like this:

With iMsg
  Set .Configuration = iConf
    .To          = "me@mydomain.com"
    .From        = "me@mydomain.com"
    .Sender      = "me2@mydomain.com"
    .Subject     = "Partner information change request"
    .TextBody    = "This is the text body."
    .HTMLBody = "<html><body><p>This is the HTML Body.</p></body></html>"
    .Send
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.)
0
lpenrodAuthor Commented:
You rock!
0
Saqib KhanSenior DeveloperCommented:
barryfandango so we can use this method to send email VIA win XP as well?
by adding the Library?
0
barryfandangoCommented:
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.)
0
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?
0
barryfandangoCommented:
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.
0
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!
0
andiwebxCommented:
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 www.sitename.com/, the asp page will send an email to  test@sitename.com, but not for test@othersitename.com.

i know it is something wrong with the STMP server, right?
0
lpenrodAuthor Commented:
Relay restriction?
0
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
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.