Welcome to Bucaro TecHelp!

Bucaro TecHelp
HTTPS Encryption not required because no account numbers or
personal information is ever requested or accepted by this site

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Sending Email With ASP

Sending email with ASP (Active Server Pages) is not difficult. You can use ASP email to create a contact form, support request form, or even perform mass emailings. CDO (Collaboration Data Objects) is the Microsoft technology that simplifies the creation of email applications.

SMTP (Simple Mail Transfer Protocol) is a service installed with IIS that allows you to send email from an ASP webpage. This article assumes SMTP is properly installed and configured on your server.

- Microsoft's previous technology to send email was CDONTS (Collaboration Data Objects for New Technology Server). With Windows 2000 server, CDONTS was replaced with CDO. CDO which provides the ability to send messages through a remote SMTP (Simple Mail Transfer Protocol) server.

Windows 2003 server doesn't install CDONTS by default, therefore if you used CDONTS in your ASP applications, you should update the code to use CDO. You can use CDO (also referred to as CDOSYS) in ASP and ASP.NET applications.

Sending a Plain Text Email

The script below demonstrates how to send a simple pre-defined plain text email message.

<%
Set objMail. = CreateObject("CDO.Message")

objMail.Subject = "Sending email with CDO"
objMail.From = "mymail@yourdomain.com"
myMail.To = "someone@domain.com"
objMail.TextBody = "This is a test message."
objMail.Send

set objMail. = Nothing
Response.Write "Message Sent"
%> 

To try the example, paste the script into a file on your ASP Web server named, for example cdotest.asp. Edit the From and To email addresses, then execute the script.

An ASP Email Contact Form

One of the most common uses of ASP email is to create a Contact Form for your Web site through which visitors can provide comments or ask questions. Below is an example of an ASP Web page for a Contact form.

<html>
<head>
<title>Email Contact Form</title>
</head>
<body>

<%
Dim strName, strEmail, strMessage

strName = Trim(Request.Form("sender"))
strEmail = Trim(Request.Form("email"))
strMessage = Trim(Request.Form("comment"))

If(strMessage <> "") Then
  Set objMail = CreateObject("CDO.Message")

  objMail.From = strEmail
  objMail.To = "mymail@yourdomain.com"
  objMail.Subject = "Contact Form from " & strName
  objMail.TextBody = strMessage
  objMail.Send

  Set objMail = Nothing

  Response.Write "Thank You"
Else
%>

Email Form<br />
<form method="post">
Name: <input type="text" name="sender" size=40></input><br />
Email: <input type="text" name="email" size=40></input><br />
Comment:<br />
<textarea name="comment" cols=40 rows=5></textarea><br />
<input type="submit" value="Submit"></input>
</form>

<% End If %>
</body>
</html>

Paste this script into a file on your Web server named, for example contact.asp. Edit the To email address to the address where you want to receive the contact form messages. You can also edit the text "Thank You" which is the message the user receives after they click the [Submit] button.

RSS Feed RSS Feed

Follow Stephen Bucaro Follow @Stephen Bucaro

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2024 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268