Home Services Toolbox Downloads Gaming Tech News About Us

Email using ASP CDONTS

Invasive Procedures blog by brenz.net

Share this page: facebook myspace twitter bebo delicious digg stumbleupon buzz fark linkedin

Sending Email via ASP CDONTS

Collaboration Data Objects for Windows NT Server (CDONTS) is a simple object library developers can use for basic mail and messaging services. CDONTS is installed as part of the optional SMTP component of Windows 2000 Server.

Implement CDONTS Email on Your Website

To send an email like this one from your .asp page using CDONTS, drop in this small snippet of code at the very top of the page (before the doctype and html tags):
if request.form("send").count > 0 then
Dim ObjMail
Set ObjMail = Server.CreateObject("CDONTS.NewMail")
ObjMail.To = "yourname@yoursite.com"
ObjMail.From = request.form("from")
ObjMail.Subject = request.form("subject")
ObjMail.Body = request.form("body")
Set ObjMail = Nothing
Response.redirect "message_sent.asp"
end if
Then, within the body of your page, an HTML form allows the user to enter their message. The code shown here makes use of the 'post-back' method to return the form data back to the same page. Thus, the code is extremely portable - once it has been written and tested, you can move this page around on your website and not have to worry about changing any form action URL's. The URL of the page in which this form resides is retrieved using the ServerVariables Collection of the Request Object.
<form action="<%= Request.ServerVariables("PATH_INFO") %>" method="post">
<input type="hidden" name="send" id="send" />
<strong>TO:</strong><br />
<em>yourname@yoursite.com</em><br /><br />
<strong>FROM:</strong><br />
<input type="text" name="from" id="from" value=""/>
<strong>SUBJECT:</strong><br />
<input type="text" size="35" name="subject" id="subject" value="" />
<strong>BODY:</strong><br />
<textarea cols="35" rows="5" name="body" id="body"></textarea><br />
<input type="submit" value="Send" />

Home Services Toolbox Downloads Gaming Tech News About Contact Us Privacy