Author: Michael Gonzalez
Frequently Answered Questions
Miscellaneous

File Text Search & Replace Utility
HTML Text Extraction using innerText
E-mail (CDONTS.NewMail) Sample Code
SQL Server 7.0/2000

Incorporating ASP and SQL Server
100's of T-SQL Scripts
Don't Use @@ERROR with UPDATE Statements
Exporting Tables to Text Files
Creating SQL Server Databases
ASP (SQL) Query Analyzer
Increasing SQL Server Performance with Indexes
Distributed SQL Server Transactions & Queries
COM/COM+ Development
What is COM?
Isn't ActiveX and COM the same?
How can Components benefit my ASPs?
Am I using COM Components now?
How do I use COM Components in my ASPs?
Creating your First COM Component
Creating a COM Component that uses ASP Intrinsic Objects
Creating a COM Component to access an MS-Access Database
MTS Component Template
MSMQ Component Template / Example

E-mail (CDONTS.NewMail) Sample Code

The form at the start page of my articles contains an e-mail form which sends form information to an e-mail ASP processing page called email.asp. It's pretty simple and sending e-mail via ASP and IIS' SMTP Service is a breeze.

If you have the SMTP Service setup and started (with the SmartHost set to point to a SMTP server), you can use the COM Component CDONTS.NewMail in your ASP pages to send e-mail to recipients!

Click HERE to download a self-extracting ZIP file that contains the email.asp page I use with the form mentioned above.


Below is the sample in JavaScript (which is what I write most of my ASP in):
if (Request.Form("msg") == "") { Response.Write("<br><br><br><font size=3><b>Oopps.. you didn't type a message!</b></font><br><br>" + "<a href='" + Request.ServerVariables("HTTP_REFERER") + "'>Click here to go back.</a>") } else { var objMail = Server.CreateObject("CDONTS.NewMail"); objMail.To = "someone@somewhere.com"; //<-- PUT A VALID E-MAIL ADDRESS HERE objMail.From = "someone@somewhere.com"; //<-- PUT A VALID E-MAIL ADDRESS HERE objMail.Subject = "Message from ASP Alliance Visitor"; objMail.Body = Request.Form("msg"); objMail.Send() var objMail = null; Response.Write("<br><br><br><font size=3><b>Thank you for your message!</b></font><br><br>" + "An e-mail has been delivered to my e-mail address (miketgonzalez@yahoo.com) with " + "the following message:<br><i>" + Request.Form("msg") + "</i><br><br>" + "<a href='" + Request.ServerVariables("HTTP_REFERER") + "'>Click here to go back.</a>") }
Below is the sample in VBScript:
If Not Request.Form("msg") <> "" Then Response.Write("<br><br><br><font size=3><b>Oopps.. you didn't type a message!</b></font><br><br>" & _ "<a href='" & Request.ServerVariables("HTTP_REFERER") & "'>Click here to go back.</a>") Else Set objMail = Server.CreateObject("CDONTS.NewMail") objMail.To = "someone@somewhere.com" '<-- PUT A VALID E-MAIL ADDRESS HERE objMail.From = "someone@somewhere.com" '<-- PUT A VALID E-MAIL ADDRESS HERE objMail.Subject = "Message from ASP Alliance Visitor" objMail.Body = Request.Form("msg") objMail.Send() Set objMail = Nothing Response.Write("<br><br><br><font size=3><b>Thank you for your message!</b></font><br><br>" & _ "An e-mail has been delivered to my e-mail address (miketgonzalez@yahoo.com) with " & _ "the following message:<br><i>" & Request.Form("msg") & "</i><br><br>" & _ "<a href='" & Request.ServerVariables("HTTP_REFERER") & "'>Click here to go back.</a>") End If
Comments & Questions Form

Send It!