home > email > asp

Sending e-mail with ASP

You can send e-mail from your website using ASP components. Two methods are available with your package: CDO, the built-in component that comes with Windows Server, or JMail, a third-party component.

Using CDO

The built-in Windows Server e-mail component is called CDO (Collaboration Data Objects). As an ASP programmer, you may be familiar with CDONTS, which was the e-mail component included with Windows NT. Microsoft has stopped supporting CDONTS. It is outdated, and no longer available with the current version of Windows Server. Korax uses the latest Windows Server products, so CDONTS is not available with your hosting package.

To use CDO, follow these steps.

  1. At the top of the web page you are sending mail from, include an HTML comment tag that will cause your ASP script to use the CDO type library. By using the type library, you can replace numeric constants with text equivalents that are easier to read. Make sure this is an HTML comment tag, placed outside of the ASP delimiters.
    <!--METADATA
        type="typelib"
        UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
        name="CDO for Windows Server Type Library"
    -->
  2. In the ASP script, create the CDO Configuration object. The Configuration property called Fields is also an object. Set the Fields properties to send mail using the local SMTP server, and call the update method on Fields.
    Set iConf = CreateObject("CDO.Configuration")
    iConf.Fields.Item(cdoSendUsingMethod) = cdoSendUsingPort
    iConf.Fields.Item(cdoSMTPServer) = "localhost"
    iConf.Fields.Update
  3. Create the CDO Message object. Message has an object called Configuration as a property. Set it to the Configuration object you created in the previous step. Set the other Message properties with the e-mail sender, recipient, subject, and body text. To send the e-mail message, call the Message object's Send method.
    Set iMsg = CreateObject("CDO.Message")
    Set iMsg.Configuration = iConf

    iMsg.To = "smith@example.com"
    iMsg.CC = "jones@example.com"
    iMsg.From = "pat@example.com"
    iMsg.Subject = "Meeting today"
    iMsg.TextBody = "Please attend today's meeting."
    iMsg.Send

    You can also send an HTML e-mail message by setting the HTMLBody property with the e-mail text, instead of the TextBody property.

    iMsg.HTMLBody = "<em>Please attend today's meeting.</em>";

For a complete list of Message object properties that can be set, read CDO Reference at the Microsoft MSDN website.

Using JMail

JMail is a free third-party ASP component included with your Windows Server web hosting package. For details on its use, read ASP components.