Click here to Skip to main content
14,217,648 members

A Beginner's Guide to CDOSYS

Rate this:
4.08 (13 votes)
Please Sign up or sign in to vote.
4.08 (13 votes)
5 Sep 2003
Use CDOSYS instead of CDONTS on Windows 2000/XP

Sample Image - cdoex.gif

Introduction

Use this example to allow users of your website to submit feedback and send emails using IIS and its SMTP service.

Background

CDOSYS is the successor of CDONTS, an easy way to send emails from webpages. Unfortunately, CDONTS was discontinued in Windows XP, so web authors must now use CDOSYS instead. CDOSYS is as easy to use as CDONTS, however CDOSYS also allows authors to create much more sophisticated emails using html and datasources.

Requirements

  • Windows 2000/XP
  • SMTP Service for IIS installed
  • Run this sample on your own computer with IIS installed.
  • Put the files in a web server directory.
  • Do not open the htm page in Windows explorer and expect it to work. You must use the internet so that IIS is involved in the processing. For example, http://www.mydomain.com/sample1.htm will work. c:\downloads\sample1\sample1.htm won't work.
  • Using JScript as the .asp language doesn't work as easily as vbscript does.

Using the code

The first step is to call the components into action...

Dim iMsg
Set iMsg = CreateObject("CDO.Message")
Dim iConf
Set iConf = CreateObject("CDO.Configuration")

Step 2 involves verifying the correct configuration settings...

Dim Flds
Set Flds = iConf.Fields
Flds("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
Flds( _
 "http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") _
  = "c:\inetpub\mailroot\pickup"
Flds.Update

Be especially mindful of the path in the code above. Step 3 shows how the message is constructed...

Set iMsg.Configuration = iConf
iMsg.To = Request.Form.Item("Email")
iMsg.From = "put_in_your_email_address_here@domain.com"
iMsg.Subject = Request.Form.Item("Subject")
iMsg.TextBody = Request.Form.Item("EContent")
iMsg.Send            

The Request.Form.Item grabs the data posted to it from the form on the sample1.htm page.

Points of Interest

This is really the tip of the iceberg. There is so much more that you could do with CDOSYS (and CDOEX). See http://msdn.microsoft.com/library/default.asp?url=/nhp/default.asp?contentid=28000408 for more details...

History

  • Sept. 6/03 - Posted this article

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

rbeckett
Web Developer
Canada Canada
It's Frum the Slum

Comments and Discussions

 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey27-Apr-12 1:30
professionalManoj Kumar Choubey27-Apr-12 1:30 
GeneralMessage Body Truncated Pin
ravi_bhartiya3-Jun-09 22:34
memberravi_bhartiya3-Jun-09 22:34 
GeneralThanks!!!!!!! Pin
alimzhan23-Jan-09 13:19
memberalimzhan23-Jan-09 13:19 
Generalsender's name along with words in subject Pin
BrendaBachman2-Mar-06 3:00
memberBrendaBachman2-Mar-06 3:00 
Generalcreate a .eml file and i move that eml file in the specific folder Pin
jituyadav6-Feb-06 20:40
memberjituyadav6-Feb-06 20:40 
GeneralFirst-Last Name Values Pin
rob365-Oct-05 9:29
memberrob365-Oct-05 9:29 
Generala question Pin
fly0912-Mar-05 18:10
memberfly0912-Mar-05 18:10 
GeneralRe: a question Pin
ghle2-Dec-10 9:03
memberghle2-Dec-10 9:03 
GeneralJScript (Using ASP and MYSQL) - EMail Pin
Kush Mashru8-Feb-05 4:53
sussKush Mashru8-Feb-05 4:53 
Hi,

I have a small problem.
I cant seem to send out an email and am always coming up with an error.
I am usign ASP and JScript and have treid to use the code given by yourself on this site.

The code is as follows:
----------------------------------------------------------------------------------------------------

<%
Dim strUseId , strPassword

strUserId = Request("UserId")
strPassword = Request("Password")

dim objConn
dim rsUsers

Set objConn = Server.CreateObject("ADODB.Connection")

objConn.Open "DSN=tilak"

set rsUsers = Server.CreateObject("ADODB.Recordset")

strSQL = "Select * from customers where Email_add = '" & strUserId & "';"

rsUsers.Open strSQL , ObjConn

If rsUsers.EOF Then
Response.write "Your email Id does not present. "
else

var conf = Server.CreateObject( "CDO.Configuration" );
conf.Fields( "http://schemas.microsoft.com/cdo/configuration/sendusing" ) = 1;
conf.Fields( "http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory" ) = "c:\\inetpub\\mailroot\\pickup";
conf.Fields.Update();

var msg = Server.CreateObject( "CDO.Message" );
msg.Configuration = conf;

msg.To = "kcmashru@aol.com";

msg.From = "password-reminder@tilak.co.uk";

msg.Subject = "Your Password - Reminder !!";

msg.TextBody = "This is a short message in text format.";
//msg.HTMLBody = "This is a short message in HTML format.";

msg.Send();

msg = null;
conf = null;

response.write "Password has been sent to your email address."

end if
%>
----------------------------------------------------------------------------------------------------

Can you please tell me what the problem is here?
The file is saved as .asp

Thanks

Kush
GeneralHelp Pin
Anonymous28-Sep-04 4:43
memberAnonymous28-Sep-04 4:43 
GeneralRe: Help Pin
Anonymous10-Oct-04 18:58
memberAnonymous10-Oct-04 18:58 
Generalmessages not being sent Pin
griffett24-Jun-04 3:19
membergriffett24-Jun-04 3:19 
GeneralRe: messages not being sent Pin
mods20051-Mar-05 4:48
membermods20051-Mar-05 4:48 
General[Message Deleted] Pin
spankle15-Jun-04 7:02
memberspankle15-Jun-04 7:02 
GeneralRe: CDOSYS vs CDONTS Pin
Anonymous15-Jun-04 18:00
memberAnonymous15-Jun-04 18:00 
GeneralCDOSYS vs CDONTS Pin
spankle15-Jun-04 7:00
memberspankle15-Jun-04 7:00 
GeneralDoesnt work Pin
MaxxxDamage23-Apr-04 19:19
memberMaxxxDamage23-Apr-04 19:19 
GeneralRe: Doesnt work Pin
raviegopal8-Jun-04 21:16
memberraviegopal8-Jun-04 21:16 
GeneralRe: Doesnt work Pin
steve72826-Jun-04 6:55
membersteve72826-Jun-04 6:55 
GeneralRe: Doesnt work Pin
Anonymous29-Oct-04 1:23
memberAnonymous29-Oct-04 1:23 
Questionc:\inetpub\mailroot\pickup ????? Pin
zahidrahim12-Mar-04 19:15
memberzahidrahim12-Mar-04 19:15 
AnswerRe: c:\inetpub\mailroot\pickup ????? Pin
Anonymous21-Mar-04 6:57
memberAnonymous21-Mar-04 6:57 
GeneralI cant download the zip Pin
Anonymous1-Feb-04 9:06
memberAnonymous1-Feb-04 9:06 
GeneralImage Pin
Anonymous11-Dec-03 9:41
memberAnonymous11-Dec-03 9:41 
Questionand jscript? Pin
Anonymous4-Nov-03 8:43
memberAnonymous4-Nov-03 8:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Article
Posted 5 Sep 2003

Stats

256.7K views
3.6K downloads
30 bookmarked