SiteExperts.com Logo Home | Community | Developer's Paradise | Jobs
User Groups | Site Tools | Site Information | Search

Inside Technique : Sending E-Mail from ASP
By Scott Isaacs

The CDONTS NewMail object is a very easy way to add e-mail capabilities to your ASP web-pages. We use this object when we want to automate e-mail from our server (eg., our Find Lost Password page). In this article, we introduce you to the NewMail object.

Sending e-mail with the NewMail object is very simple. Below we construct and send an e-mail message to a fictitious e-mail address:

<%
  Dim oMailMessage

  ' Instantiate a NewMail object
  Set oMailMessage = Server.CreateObject("CDONTS.NewMail") 

  ' Send an email to to@example.com from from@example.com
  oMailMessage.from = "from@example.com"
  oMailMessage.to = "to@example.com"
  oMailMessage.subject = "Test Subject"
  oMailMessage.body = "Wow - This is cool!"
  oMailMessage.Send()

  ' Release the NewMail object
  Set oMailMessage = Nothing ' Release the object
%>

The above script is a verbose way to specify your message. You can shrink the above code down to 4 lines by specifying all the e-mail arguments directly in the Send() method.

<%
  Dim oMailMessage

  ' Instantiate a NewMail object
  Set oMailMessage = Server.CreateObject("CDONTS.NewMail") 

  ' Send an email to to@example.com from from@example.com
  oMailMessage.Send("from@example.com", "to@example.com", "Demo Subject", _ 
                  "Wow! Sending mail is cool")

  ' Release the NewMail object
  Set oMailMessage = Nothing ' Release the object
%>

Next we explain how to send the same e-mail to multiple recipients or to send personalized e-mail messages.