ASP Hosting - ASP Web Hosting  
ASP Hosting Plans Internet Marketing SQL Hosting Plans Customer Support Contact Us

ASP Web Page Email Using Microsoft's CDONTS

As an ASP web site hosting service, HyperlinkHost offers the following script for web based email. Web based email using CDONTS can be run on our Windows 2000 servers.

CDONTS stands for 'Collaboration Data Objects for Windows NT Server' and as the name suggest it is for NT. Win9x users don't have this component. The CDONTS component is installed when you install IIS on NT4 and Windows 2000. Although the component will run on Windows XP, Microsoft have decided to remove the component from IIS 5.1 on Windows XP, so you will have to track down a copy of the cdonts.dll and register it on the IIS web server.

To use this component to send email you also need the SMTP Server that ships with IIS 4 or 5 installed on the web server. The SMTP server is usually installed by default with the standard IIS installation.

First we need to create the variables that we are going to be using in this script.

<%
'Dimension variables
Dim objCDOMail      'Holds the CDONTS NewMail Object


Next we need to create an instance of the 'CDONTS NewMail' object on the server.

'Create the email server object
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")


Once the 'NewMail' object has been created on the server we can use various properties and methods of the 'NewMail' object to build the email.

First we are going to use the 'From' property to let the recipient of the email know who the email is from. If you leave this property out or do not have a properly format email address the email will fail.

'Who the email is from
objCDOMail.From = "me@myDomain.com"


Now we need to place a string value representing the email address of the person you want to receive the email into the 'To' property of the 'NewMail' object.

'Who the email is sent to
objCDOMail.To = "theirEmail@theirDomain.com"


The next property 'Cc' holds the email address of the people you wish to receive Carbon Copies of the email.

You can place one or more recipient email addresses separated by either a comma (,) or a semicolon (;). Make sure all the email address are properly formatted or the email will fail.

This property can be left out if you don't want any carbon copies of the email sent.

'Who the carbon copies are sent to
objCDOMail.Cc = "myFriend1@theirDomain.com;myFriend2@anotherDomain.com"


The 'Bcc' property holds the email address of the people you wish to receive Blind Copies of the email. The formatting of the email addresses is the same as for the 'Cc' property above.

Again if you don't want to send any blind copies of the message you can leave this property out.

'Who the blind copies are sent to
objCDOMail.Bcc = "myFriend1@theirDomain.com;myFriend2@anotherDomain.com"


In the next line we use the 'Subject' property to set the subject of the email.

'Set the subject of the email
objCDOMail.Subject = "Inquiry sent from my web site"


As well as sending plain text emails, you can also format the body of the email using HTML. The default is Text but if you wish to format the email using HTML then you will need to use the 'BodyFormat' property with the integer value of '0' for HTML or '1' for Text.

If you leave this property out the email will be sent as plain text format.

'Set the email body format (0=HTML 1=Text)
objCDOMail.BodyFormat = 0


If you wish to use HTML formatting in the email, as well as setting the 'BodyFormat' property above to HTML, you will also need to set the 'MailFormat' property to MIME. Again this property uses and integer value of '0' for MIME and '1' for Text.

The default is text so if your email is text only you can leave this property out.

'Set the mail format (0=MIME 1=Text)
objCDOMail.MailFormat = 0


The next property is the 'Body' property. This property holds the main part of the email with the message you are sending.

If you have set the 'BodyFormat' property to HTML and the 'MailFormat' to MIME then you can use HTML to format your email message. 'eg. <h2>Hello</h2><br><b>This is my email in HTML format</b>'.

If you want to send the email as text then you can just enter text instead. 'eg. Hello This is my email in Text format'.

'Set the main body of the email
objCDOMail.Body = "<h2>Hello</h2><br><b>This is my email in HTML format</b>"


The 'Importance' property tells the mail messaging system when to schedule delivery of the email.

For this property there is 3 different integer values; 0 - Low (the email will be sent during times of low system use); 1 - Normal (the message is sent at regular delivery times); 2 - High (the system will attempt to send the message immediately).

If this property is left out the default is Normal.

'Importance of the email (0=Low, 1=Normal, 2=High)
objCDOMail.Importance = 1


Once all the properties for the email are set we can now send the email using the 'Send' property.

'Send the email
objCDOMail.Send


Finally once the email has been sent we close the server object releasing server resources.

'Close the server object
Set objCDOMail = Nothing
%>

 

Put all together, the code looks like this-

<%
'Dimension variables
Dim objCDOMail      'Holds the CDONTS NewMail Object

'Create the email server object
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")

'Who the email is from
objCDOMail.From = "me@myDomain.com"

'Who the email is sent to
objCDOMail.To = "theirEmail@theirDomain.com"

'Who the carbon copies are sent to
objCDOMail.Cc = "myFriend1@theirDomain.com;myFriend2@anotherDomain.com"

'Who the blind copies are sent to
objCDOMail.Bcc = "myFriend1@theirDomain.com;myFriend2@anotherDomain.com"

'Set the subject of the email
objCDOMail.Subject = "Inquiry sent from my web site"

'Set the email body format (0=HTML 1=Text)
objCDOMail.BodyFormat = 0

'Set the mail format (0=MIME 1=Text)
objCDOMail.MailFormat = 0

'Set the main body of the email
objCDOMail.Body = "<h2>Hello</h2><br><b>This is my email in HTML format</b>"

'Importance of the email (0=Low, 1=Normal, 2=High)
objCDOMail.Importance = 1

'Send the email
objCDOMail.Send

'Close the server object
Set objCDOMail = Nothing
%>

There are other methods and properties of the 'NewMail CDONTS' object but these are the most common properties used to send an email from your web site.

 

Main Page  |  Hosting Plans  |  E-Commerce  |  Sign Up Now!  |  Site Map

asp web site hosting by HyperlinkHost.com