在win2003上用cdo代替CDONTS發郵件

來源:互聯網
上載者:User
發郵件|發郵件 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|            </



相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。