Solved

Send email using CDOSYS

Posted on 2003-11-11
14
2,050 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:lpenrod
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
  • +1
14 Comments
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 9723674
> Set iMsg = CreateObject("CDO.Message")

maybe try

Set iMsg = Server.CreateObject("CDO.Message")
0
 
LVL 3

Author Comment

by:lpenrod
ID: 9723759
No change.
0
 
LVL 3

Author Comment

by:lpenrod
ID: 9723968
Not sure if it is relevant.  The box is a Windows 2003 server running IIS6.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 3

Accepted Solution

by:
barryfandango earned 500 total points
ID: 9723970
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
 
LVL 3

Author Comment

by:lpenrod
ID: 9724015
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
 
LVL 3

Assisted Solution

by:barryfandango
barryfandango earned 500 total points
ID: 9724050
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
 
LVL 3

Author Comment

by:lpenrod
ID: 9724089
You rock!
0
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 9724108
barryfandango so we can use this method to send email VIA win XP as well?
by adding the Library?
0
 
LVL 3

Expert Comment

by:barryfandango
ID: 9724124
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
 
LVL 3

Author Comment

by:lpenrod
ID: 9724133
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
 
LVL 3

Expert Comment

by:barryfandango
ID: 9724156
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
 
LVL 3

Author Comment

by:lpenrod
ID: 9724173
Got you.  I forgot that the IIS server running the code is internal and therefore would be allowed to send mail.

Thanks again!
0
 

Expert Comment

by:andiwebx
ID: 10442363
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
 
LVL 3

Author Comment

by:lpenrod
ID: 10443196
Relay restriction?
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question