QQRead:http://www.qqread.com/asp/2006/10/e241375.html
Introduction
CDONTS was actually replaced by CDO already in Windows 2000 and Windows XP. But these Operating Systems supported CDONTS, and you could use CDONTS. Windows Server 2003 does not support CDONTS, and we are forced to use CDO. This tutorial is a crash course in CDO, and we will create a few simple web forms for sending emails with CDO and ASP.
Before we begin
Before I show you any code, there are a few things we must do to get this to work. The first thing is set up a web server – IIS 6.0. You can start the wizard for the installation of IIS 6.0 from Manage Your Server (Start->Programs->Administrative Tools->Manage Your Server).
Click Add or remove a role.
Select Application Server
You do not need ASP.NET nor FrontPage Server Extensions for this tutorial
But that is not enough; we also need the SMTP server to send our emails, though I will also show you how to use a remote server instead of the local. So, open up Add or Remove Programs from the Control Panel.
Click Add/Remove Windows Applications
Highlight Application Server, and click Details
Highlight Internet Information Services (IIS) and click Details
Select SMTP Service and click OK, and finally Next
We are almost ready for the code writing now, but since IIS 6.0 is locked down by default, we have to go to the Internet Information Services Manager (Start->Program->Administrative Tools) and enable the ASP extension.
When the IIS Manager has started, click on Web Service Extensions in the left pane.
Select Active Server Pages, and click on Allow
That’s it! We are now ready for the fun part, the coding!
A simple text email
So, start your favorite text editor, and type this:
01|<%
02|If Request.Form("btnSend").Count > 0 Then
03|
04| Set objMessage = CreateObject("CDO.Message")
05| objMessage.Subject = Request.Form("subject")
06| objMessage.Sender = Request.Form("From")
07| objMessage.To = Request.Form("To")
08| objMessage.TextBody = Request.Form("message")
09| objMessage.Send
10| Response.Redirect("Sent.HTML")
11|End If
12|%>
13|
14|<HTML>
15| <head>
16| <title>Send email with CDO</title>
17| </head>
18| <body>
19| <form name="sendEmail" action="EmailWithCDO.ASP" method="post">
20| <table>
21| <tr>
22| <td>Subject:</td>
23| <td><input type="text" name="subject" /></td>
24| </tr>
25| <tr>
26| <td>From:</td>
27| <td><input type="text" name="from" /></td>
28| </tr>
29| <tr>
30| <td>To: </td>
31| <td><input type="text" name="to" /></td>
32| </tr>
33| <tr>
34| <td valign="top">Message: </td>
35| <td><textarea name="message" rows="6" cols="30">
36|</textarea></td>
37| </tr>
38| <tr>
39| <td colspan="2"><input type="submit" name="btnSend"
40|value="Send" /></td>
41| </tr>
42| </table>
43| </form>
44| </body>
45|</HTML>
And now some explanation to this code. On line 2 we make sure that the form has been submitted. If it has, the count for the send button will be greater than 0. Line 4 creates a reference to the CDO component. Then, on line 5 to 8, we fill in subject, sender, receiver, and the text body. We do not fill out the From Property. The difference between From and Sender is that Sender identifies the user that actually submits the message, but From on the other hand, designates the author(s). Line 9 sends the email, and on line 10, we redirect the user to another page, with a message that the email has been sent. The rest of the code is pure HTML, and this tutorial assumes you have this knowledge.
So, browse the file, fill in the form, and click Send. Wait a while, and soon you will receive an email (you did change the email address to you own, didn’t you?).
This was a simple example of using CDO. And yes, it is this simple!
A simple HTML email
So, we now know how to send a text email. But what about a HTML email? Well, it is almost as simple as a text email. I will also introduce another new thing here, Blind Carbon Copy (Bcc), and Carbon Copy (Cc). So, what are we waiting for, let’s write some code!
01|<%
02|
03|If Request.Form("btnSend").Count > 0 Then
04|
05| Set objMessage = CreateObject("CDO.Message")
06| objMessage.Subject = Request.Form("subject")
07| objMessage.Sender = Request.Form("From")
08| objMessage.To = Request.Form("To")
09| objMessage.Bcc = Request.Form("Bcc")
10| objMessage.Cc = Request.Form("Cc")
11| objMessage.HTMLBody = Request.Form("message")
12| objMessage.Send
13| Response.Redirect("Sent.HTML")
14|End If
15|%>
16|
17|<HTML>
18| <head>
19| <title>Send email with CDO</title>
20| </head>
21| <body>
22| <form name="sendEmail" action="EmailWithCDO2.ASP" method="post">
23| <table>
24| <tr>
25| <td>Subject:</td>
26| <td><input type="text" name="subject" /></td>
27|&nb
更多内容请看邮件服务器专题、win2003频道专题,或进入讨论组讨论。
Introduction
CDONTS was actually replaced by CDO already in Windows 2000 and Windows XP. But these Operating Systems supported CDONTS, and you could use CDONTS. Windows Server 2003 does not support CDONTS, and we are forced to use CDO. This tutorial is a crash course in CDO, and we will create a few simple web forms for sending emails with CDO and ASP.
Before we begin
Before I show you any code, there are a few things we must do to get this to work. The first thing is set up a web server – IIS 6.0. You can start the wizard for the installation of IIS 6.0 from Manage Your Server (Start->Programs->Administrative Tools->Manage Your Server).
Click Add or remove a role.
Select Application Server
You do not need ASP.NET nor FrontPage Server Extensions for this tutorial
But that is not enough; we also need the SMTP server to send our emails, though I will also show you how to use a remote server instead of the local. So, open up Add or Remove Programs from the Control Panel.
Click Add/Remove Windows Applications
Highlight Application Server, and click Details
Highlight Internet Information Services (IIS) and click Details
Select SMTP Service and click OK, and finally Next
We are almost ready for the code writing now, but since IIS 6.0 is locked down by default, we have to go to the Internet Information Services Manager (Start->Program->Administrative Tools) and enable the ASP extension.
When the IIS Manager has started, click on Web Service Extensions in the left pane.
Select Active Server Pages, and click on Allow
That’s it! We are now ready for the fun part, the coding!
A simple text email
So, start your favorite text editor, and type this:
01|<%
02|If Request.Form("btnSend").Count > 0 Then
03|
04| Set objMessage = CreateObject("CDO.Message")
05| objMessage.Subject = Request.Form("subject")
06| objMessage.Sender = Request.Form("From")
07| objMessage.To = Request.Form("To")
08| objMessage.TextBody = Request.Form("message")
09| objMessage.Send
10| Response.Redirect("Sent.HTML")
11|End If
12|%>
13|
14|<HTML>
15| <head>
16| <title>Send email with CDO</title>
17| </head>
18| <body>
19| <form name="sendEmail" action="EmailWithCDO.ASP" method="post">
20| <table>
21| <tr>
22| <td>Subject:</td>
23| <td><input type="text" name="subject" /></td>
24| </tr>
25| <tr>
26| <td>From:</td>
27| <td><input type="text" name="from" /></td>
28| </tr>
29| <tr>
30| <td>To: </td>
31| <td><input type="text" name="to" /></td>
32| </tr>
33| <tr>
34| <td valign="top">Message: </td>
35| <td><textarea name="message" rows="6" cols="30">
36|</textarea></td>
37| </tr>
38| <tr>
39| <td colspan="2"><input type="submit" name="btnSend"
40|value="Send" /></td>
41| </tr>
42| </table>
43| </form>
44| </body>
45|</HTML>
And now some explanation to this code. On line 2 we make sure that the form has been submitted. If it has, the count for the send button will be greater than 0. Line 4 creates a reference to the CDO component. Then, on line 5 to 8, we fill in subject, sender, receiver, and the text body. We do not fill out the From Property. The difference between From and Sender is that Sender identifies the user that actually submits the message, but From on the other hand, designates the author(s). Line 9 sends the email, and on line 10, we redirect the user to another page, with a message that the email has been sent. The rest of the code is pure HTML, and this tutorial assumes you have this knowledge.
So, browse the file, fill in the form, and click Send. Wait a while, and soon you will receive an email (you did change the email address to you own, didn’t you?).
This was a simple example of using CDO. And yes, it is this simple!
A simple HTML email
So, we now know how to send a text email. But what about a HTML email? Well, it is almost as simple as a text email. I will also introduce another new thing here, Blind Carbon Copy (Bcc), and Carbon Copy (Cc). So, what are we waiting for, let’s write some code!
01|<%
02|
03|If Request.Form("btnSend").Count > 0 Then
04|
05| Set objMessage = CreateObject("CDO.Message")
06| objMessage.Subject = Request.Form("subject")
07| objMessage.Sender = Request.Form("From")
08| objMessage.To = Request.Form("To")
09| objMessage.Bcc = Request.Form("Bcc")
10| objMessage.Cc = Request.Form("Cc")
11| objMessage.HTMLBody = Request.Form("message")
12| objMessage.Send
13| Response.Redirect("Sent.HTML")
14|End If
15|%>
16|
17|<HTML>
18| <head>
19| <title>Send email with CDO</title>
20| </head>
21| <body>
22| <form name="sendEmail" action="EmailWithCDO2.ASP" method="post">
23| <table>
24| <tr>
25| <td>Subject:</td>
26| <td><input type="text" name="subject" /></td>
27|&nb
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
相关专题
- asp+ajax打造无刷新新闻评论系统 (846次浏览)
- 绝对免费顶级域名+免费500MB ASP?? (728次浏览)
- ASP后门之终极伪装 (601次浏览)
- FTP的安全问题 《转》 (589次浏览)
- 如何正确显示数据库中的图片 (503次浏览)
- 用户登录/注册程序——Flash+ASP (492次浏览)
- SQL注入漏洞全接触 (381次浏览)
- asp+sqlserver 分页方法(不用存储过程) (314次浏览)
- Windows操作系统出现死机故障的解决方法 (202次浏览)
- 对ASP 动态包含文件方法的改进 (152次浏览)



