CDOSYS or CDONTS, Which Will It Be?
page 1 of 1
Published: 05 Jan 2005
Unedited - Community Contributed
Abstract
Before starting, I should mention that if you have never used CDONTS or CDOSYS and just want to find out how to create a feedback form, read on, this is also written for you. This article is targeted at Classic ASP developers.
by Web Team at ORCS Web
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 44831/ 30

Before starting, I should mention that if you have never used CDONTS or CDOSYS and just want to find out how to create a feedback form, read on, this is also written for you. This article is targeted at Classic ASP developers. If you are using ASP.NET, you may want to check out an article by Brad Kingsley on Sending Email from ASP.NET.

Now back to the topic at hand. If you currently use CDONTS for sending email, the time may have come to bury the dead and move on. Microsoft introduced CDONTS with IIS4, allowing programmers to easily send email from ASP without purchasing and installing 3rd-party components. But, like any evolving technology, a new version has taken center stage. CDOSYS is Microsoft's new and improved interface for SMTP email which was introduced in Windows 2000.

So, the question: "Why should I switch to CDOSYS when my current CDONTS code works great?". Let me give a few reasons:

  • CDONTS has been deprecated in IIS5 and is completely removed from Windows Server 2003, and even Windows XP. Yes, it is possible to install on Windows Server 2003 but with the performance improvements and other enhancements, there should be no need to do so.
  • CDOSYS carries less overhead than CDONTS.
  • HTML functionality is much improved with automatic generation of the TextBody by just setting the HTMLBody property.
  • There are some new properties and methods that should have been included with CDONTS but weren't.

Let's look at an example.

 
01: <% Option Explicit %>
02: <% 
03: 'Declare variables 
04: Dim sMsg 
05: Dim sTo 
06: Dim sFrom 
07: Dim sSubject 
08: Dim sTextBody 
09: Dim sHTMLBody 
10: 
11: 'Get data from previous page
12: sTo = Request("sTo") 
13: sFrom = Request("sFrom") 
14: sSubject = Request("sSubject")
15: sTextBody = Request("sTextBody") 
16: sHTMLBody = Request("sHTMLBody") 
17: 
18:'Only run this if it's not the first time 
19: If Request.Form("Submit") <> "" Then
20: 
21: Dim objMail 
22: 'Create the mail object 
23: Set objMail = Server.CreateObject("CDO.Message")
24: 'Set key properties 
25: objMail.From = sFrom 
26: objMail.To = sTo 
27: objMail.Subject= sSubject 
28: objMail.TextBody = sTextBody 
29: objMail.HTMLBody = sHTMLBody 
30: 
31:'Send the email 
32: objMail.Send 
33: 'Set sMsg which will be used later 
34: sMsg = "Your message was sent to: " & sTo 
35: 
36: 'Clean-up 
37: Set objMail = Nothing
38: 
39: End If 
40: %>
41: <html>
42: <head><title>SendMail</title></head>
43: <body>
44:  <form action="<%=Request.ServerVariables("PATH_INFO")%>" method="post">
45:  <table>
46:    <tr>
47:      <td>Send To:</td>
48:      <td><input type="text" name="sTo" value="<%=sTo%>"></td>
49:    </tr>
50:    <tr>
51:      <td>Send From:</td>
52:      <td><input type="text" name="sFrom" value="<%=sFrom%>"></td>
53:    </tr>
54:   <tr>
55:      <td>Message Subject:</td>
56:      <td><input type="text" name="sSubject" value="<%=sSubject%>"></td>
57:    </tr>
58:    <tr>
59:      <td>Message Text Body:</td>
60:      <td><textarea cols="60" rows="5" name="sTextBody">
61:         <%=sTextBody%></textarea></td>
62:    </tr>
63:    <tr>
64:      <td>Message HTML Body:</td>
65:      <td><textarea cols="60" rows="5" name="sHTMLBody">
66:         <%=sHTMLBody%></textarea></td>
67:    </tr>
68:    <tr>
69:      <td> </td>
70:      <td><input type="submit" name="Submit" value="Submit"></td>
71:    </tr>
72:  </table>
73:  <hr>
74:  <%=sMsg%>
75:  </form>
76: </body>
77: </html>
    

The above code in an ASP page uses CDOSYS and will allow the user to specify the To, From, Subject and both the Text and HTML bodies. Just cut and past into a blank page, remove the line numbers and save with an extension of .asp and this should work for you. In a real world example, you probably don't need both body options but this lets you see how easy you can set each part. In fact, if you just add to the HTMLBody property without adding the TextBody property, the TextBody will be generated automatically for you for backward compatibility with older email clients. Nice! Notice that the Body Property has been replaced with TextBody and HTMLBody and that the BodyFormat doesn't exist.

Even with the added features of CDOSYS, you'll find it is as easy as ever to work with. For those that have been loyal to third-party components, CDOSYS may do everything you need. Not only that, if you're using Windows 2000 or Windows XP, it's available to you as we speak.

All the best!

For more Information:

Visit Microsoft's documentation directly: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/_cdosys_imessage_interface.asp

By Scott Forsyth, a senior web specialist at ORCS Web, Inc. - a company that provides managed hosting services for clients who develop and deploy their applications on Microsoft Windows platforms.



User Comments

Title: CDOSYS Inbox   
Name: Jyoti
Date: 2011-01-01 2:24:49 PM
Comment:
The article is great and works fine. Can you please assist me creating a inbox using cdosys with out ms xchange server. I just want to display the mails of my inbox into my website. I could do it with cdonts.session objects. But cdonts doesn't work on my webserver anymore. Please help.
Title: Mr   
Name: Rao
Date: 2010-07-02 3:11:58 AM
Comment:
Thank u so much for this code. It's working fine
Title: CDO.Message.1 error '80040220'   
Name: shant1976
Date: 2009-11-04 5:48:27 PM
Comment:
Try the code posted on:-

http://prabhat.me/2009/11/04/send-e-mail-using-cdo/
Title: ukt   
Name: naren
Date: 2009-06-30 4:00:44 AM
Comment:
Hey i struck in this method....
but here u solve my problem in easy way....
thanks...
Title: Ray   
Name: Scott Forsyth
Date: 2009-01-22 11:55:57 AM
Comment:
Hi Ray,

XP doesn't have cdosys installed by default. If you're using ASP.NET, I suggest looking at the System.Net.Mail namespace instead. This article is dated now and I would recommend using a newer method.

If you are using Classic ASP, then sure, CDOSYS still works. If the email didn't come through, it's probably the smtp server configuration, and not cdosys. Try doing a manual test of your smtp server using Telnet: http://weblogs.asp.net/owscott/archive/2005/03/15/Troubleshooting-email_2C00_-the-Telnet-way.aspx
Title: mr   
Name: ray brown
Date: 2009-01-22 8:52:06 AM
Comment:
I sent u an email yesterday about sendmail not working. I am assuming that Win XP Prof automatically included the dll for CDOSYS. I negative, how can I chk its availability, if not included what is the easiest way to access it and install?
Title: Ray   
Name: Brown
Date: 2009-01-21 6:08:12 PM
Comment:
Excellent article, for introducing a replacement for CDONTS which I installed 4 yrs ago. I have cut and paste the arlicle and tryed to run the script on my htt:localhost, regrettably there is no sign of an email in my inbox. No errors are displayed, msg states msg has been sent. Could I have a problem with the SMTP settings on IIS, it is an unknown area for me to configure SMTP on IIS, I am running Windows XP Professional.
Title: Does it require SMTP?   
Name: Thomas
Date: 2008-01-12 10:41:23 AM
Comment:
Does it require SMTP to be installed from IIS?
Title: CDOSYS or CDONTS, Which Will It Be?   
Name: Scott Forsyth
Date: 2007-06-22 4:16:23 PM
Comment:
Hi Brenda,

Yes, this will work with ASP 3.0. If it works without any errors, then it is probably something with your mail server, and probably not your code. Here's a good way to do a mail test from your web server to confirm that it is set up correctly:
http://weblogs.asp.net/owscott/archive/2005/03/15/Troubleshooting-email_2C00_-the-Telnet-way.aspx
Title: CDOSYS or CDONTS, Which Will It Be?   
Name: Brenda
Date: 2007-06-22 10:51:52 AM
Comment:
Very good article. I am new to ASP and need to be able to email from a web page. I tried the code. All seems to go well until I check if I've got the email and no joy:-( Does this work with ASP 3? Many thanks. Brenda
Title: Thanks   
Name: Anuj
Date: 2007-04-03 6:04:10 AM
Comment:
hello sir

This is excellent article.

Thanks
Anuj
anuj_rajput@yahoo.com
Title: Re: Explanation Needed   
Name: Scott Forsyth
Date: 2006-08-28 8:37:04 AM
Comment:
Hi Arthanari,

The user comments mentioned quite a few things to check. The sendusing is a generic error that could be caused from a number of possible things.

My suggestions are:
- review all points in the user comments and make sure you've tried them all
- try a telnet test from the web server using the smtp port you specify in your code (or use 'localhost' for the default)
http://weblogs.asp.net/owscott/archive/2005/03/15/394681.aspx
- use filemon from www.sysinternals.com to confirm that there aren't any file permissions holding it back.
Title: Explanation needed   
Name: Arthanari
Date: 2006-08-28 3:47:44 AM
Comment:
hi Scott Forsyth,

Your coding is very useful to me.

am also getting errory like :
CDO.Message.1 error '80040220'

The "SendUsing" configuration value is invalid.

you explained some what in usercomments sections, But i need more specific explaination for this error,

thankx

regards,
Artha (arthanari@maxval-soft.com)
MaxVal-IP
Title: How do I get it to email more than one field   
Name: Scott Forsyth
Date: 2006-07-25 9:11:02 AM
Comment:
Hi Shona,

Thanks for posting your code example. You're really close, there is only one more thing to consider. When you set sTextBody=something, it replaces whatever was there already, so the trick is to add whatever was previously there along with the new addition. So the 2nd sTextBody line should be something like this:

sTextBody = sTextBody & "Surname: " & Request("sSurname") & VbCrLf

Using this method, you can add any new field that you want.

Scott
Title: How do get it to email more than one field   
Name: Shona
Date: 2006-07-25 3:38:48 AM
Comment:
Hi

I've been working on this that seems for days but don't seem to be able to get anywhere!

This is the script and what I want it to do is email the information in the field Surname and ChristianName. I can get it to do one without the other.

<% Option Explicit %>
<%
'Declare variables
Dim sMsg
Dim sTo
Dim sFrom
Dim sSubject
Dim sTextBody



Dim sName
Dim sstrBody
Dim sChristianName
Dim sSurname
Dim strBody
Dim sMessage






sTextBody = "ChristianName: " & Request("sChristianName") & VbCrLf
sTextBody = "Surname: " & Request("sSurname") & VbCrLf







'Only run this if it's not the first time
If Request.Form("Submit") <> "" Then

Dim objMail
'Create the mail object
Set objMail = Server.CreateObject("CDO.Message")
'Set key properties
objMail.From = "email@aol.com"
objMail.To = "email@aol.com"
objMail.Subject = sSubject
objMail.TextBody = sTextBody


objMail.Send



'Clean-up
Set objMail = Nothing

End If
%>

It would help to be able to do this but then I also need to email the information from dropdown boxes and checkboxes so any information here would also be great.

Thanks Shona
Title: to create a form contains of userid,password,address   
Name: Scott Forsyth
Date: 2006-07-15 10:51:40 AM
Comment:
Hi Ram,

For email ASP.NET, I suggest going to this site:
http://www.systemnetmail.com/

Scott
Title: to create a form contains of userid,password,address   
Name: ram
Date: 2006-07-15 10:26:15 AM
Comment:
please send it to me in c# or asp.net
Title: Basic questions   
Name: Scott Forsyth
Date: 2006-07-10 8:29:46 PM
Comment:
Hi Tc77tek,

Not having a good error to work with is one of the most difficult development issues. If it's classic ASP, you should be able to get better errors by changing IE.

http://www.orcsweb.com/support/faq.aspx#500

Hopefully this allows you to get the actual error to work with.

Thanks,
Scott
Title: Basic questions   
Name: Tc77tek
Date: 2006-07-10 4:52:41 PM
Comment:
hi there. I tried this code, i have an extremely simply website i created but need a feed back form, my boss hates the mailto forms, so i need to use ASP to create a behind the scenes mailfunction. I have our site hosted on a third party host, and as they are not the developer of the site they will not really assist me with my my forms just not working. I get a darned generic HTTP 500 - Internal server error
Internet Explorer error. Do i need to have some server side applications installed there that i dont know about? I am using dreamweaver and its a nice simple app allowing for quick editing; but i am just stuck. my boss is breathing down my neck because he hates this darned mailto: thinks its scares the clients away. HELP please.
Title: send using   
Name: Scott Forsyth
Date: 2006-06-08 9:46:53 AM
Comment:
Hi tripti,

If you are getting the 'send using' error, you already have everything installed that needs to be installed. There are a few possiblities as to permission issues though. Have you read the other user comments and replies on this page? They cover a number of the common solutions.
Title: send using   
Name: tripti
Date: 2006-06-08 2:58:00 AM
Comment:
Hi i am working in Windows 2000 OS. I have encountered the below error.Can you find me a solution. Please mail to triha@rediffmail.com

The "SendUsing" configuration value is invalid.

do i need to install Microsoft Exchange server on my system? what are the other system requirements to make ur code work on my system?
Title: CDO.Message.1 error '80040220' WinXP-Professional   
Name: Scott Forsyth
Date: 2006-03-31 9:07:25 AM
Comment:
That error is so generic it could be anything. There are a number of tips in the comments above this one, have you checked them all?

Another thing to try is to use filemon from www.sysinternals.com, it will tell you if there is a permission issue. The drop folder needs to have proper permissions.

You may also want to test your server's smtp ability using telnet just to make sure it's working correctly: http://weblogs.asp.net/owscott/archive/2005/03/15/394681.aspx.

If you have IIS SMTP installed then make sure to go to the relay settings and allow 127.0.0.1 as an approved IP address. That is a required setting in IIS.
Title: CDO.Message.1 error '80040220' WinXP-Professional   
Name: SoloVision
Date: 2006-03-31 3:42:28 AM
Comment:
CDO.Message.1 error '80040220'
The "SendUsing" configuration value is invalid.

In running WinXP-P, when it runs on 'localhost' it works fine but when it runs on my hosting server it raises this error. server is also running WinXP-P on it.

thanks in advance
Title: The "SendUsing" configuration value is invalid in Windows 2003   
Name: Scott Forsyth
Date: 2006-03-27 10:10:04 AM
Comment:
Hi Monde,

On Windows Server 2003, if you don't specify the default smtp server, it needs to obtain that from the IIS metabase. That isn't allowed by default in IIS6, but you can add it with metaacl.vbs. Google and download a copy of metaacl.vbs and the run the following:

cscript metaacl.vbs "IIS://Localhost/smtpsvc" IIS_WPG RE
cscript metaacl.vbs "IIS://Localhost/smtpsvc/1" IIS_WPG RE

This will give the IIS_WPG group read permissions to the smtpsrv node so that you'll be able to obtain the default SMTP server without specifically setting it in code. This will often resolve the error that you have run into.
Title: Good Article   
Name: Monde Masiko
Date: 2006-03-27 3:44:43 AM
Comment:
I Still get the Error

CDO.Message.1 error '80040220'
The "SendUsing" configuration value is invalid.
/EmailPassword.asp, line 134

Do i Need to Do Something ON MY Server, Im Running Windows Server 2003, Help contact me momoskills@yahoo.com
Title: Mr   
Name: Taylor Boy
Date: 2006-03-13 12:01:39 PM
Comment:
Thanks this excelent works perfect good job
Title: SendUsing   
Name: Scott Forsyth
Date: 2006-03-06 9:22:10 AM
Comment:
Siva, the SendUsing configuration value is invalid is a difficult one to troubleshoot because it's so generic.

Make sure permissions to the component are good and that your default SMTP server (usually 'localhost') allows relaying without authentication if that is what you're doing from code.

There are a number of other things that could keep it from working good, but those are the first things to check.
Title: Can you help me.. I tried but got an error.. pls reply asap   
Name: Siva Praveen
Date: 2006-03-06 7:29:00 AM
Comment:
Hi i am working in Windows NT OS. I have encountered the below error.Can you find me a solution. Please mail to sivapraveen.natti@cognizant.com

CDO.Message.1 error '80040220'
The "SendUsing" configuration value is invalid.
/Main/test1.asp, line 32

Regards,
Siva Praveen
Title: Encouraging   
Name: rgw
Date: 2006-02-13 4:26:25 PM
Comment:
i encourage you to keep this good work, as you know the simplest it is the better it will become.
Title: eng   
Name: muhammad
Date: 2005-12-15 5:15:18 AM
Comment:
thankx alot
Title: How to set the   
Name: Bagadhur
Date: 2005-09-28 5:54:08 AM
Comment:
Add some extra properties like ReplyTo , BodyFormat.Charset
Title: No New Matter   
Name: Harish
Date: 2005-06-30 3:00:34 AM
Comment:
All websites explain about sending mail, so this site is
waste one
Title: Hmmm what am i doing wrong?   
Name: Lewis
Date: 2005-03-10 11:41:50 AM
Comment:
CDO.Message.1 error '80040220'

The "SendUsing" configuration value is invalid.

/contact.asp, line 32


this is the error i get... looked for ways round it cant find anything. any help at all? email me at the.loxs@gmail.com thanks
Title: ITAS4   
Name: Ed Youn
Date: 2005-02-17 6:37:45 PM
Comment:
Thank-you! How do you attach a file?
Title: Good Article for Beginners   
Name: Rizwan Tasadduq
Date: 2005-01-15 3:03:30 AM
Comment:
This is very simple and excellent article for new comers.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2017 ASPAlliance.com  |  Page Processed at 2017-09-24 1:45:03 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search