Solved

Send email using CDOSYS

Posted on 2003-11-11
14
2,048 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
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 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