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