How to send HTML-formatted mail over SMTP by using CDONTS (189945)



The information in this article applies to:

  • Collaboration Data Objects (CDO) for NTS 1.2

This article was previously published under Q189945

SUMMARY

This article contains sample code that sends HTML-formatted mail from an Active Server Page (ASP) using CDONTS (Collaboration Data Objects for Microsoft Windows NT Server). You can use this code to programmatically send rich text and graphics embedded in a message.

MORE INFORMATION

Copy the following code into an Active Server Page on an Internet Information Server (IIS) computer that has CDONTS installed:

Sample code

    <%@ Language=VBScript %>
    <HTML>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    <%

    Dim myMail
    Dim HTML
    Set myMail = CreateObject("CDONTS.NewMail")

    HTML = "<!DOCTYPE HTML PUBLIC""-//IETF//DTD HTML//EN"">"
    HTML = HTML & "<html>"
    HTML = HTML & "<head>"
    HTML = HTML & "<meta http-equiv=""Content-Type"""
    HTML = HTML & "content=""text/html; charset=iso-8859-1"">"
    HTML = HTML & "<meta name=""GENERATOR"""
    HTML = HTML & " content=""Microsoft Visual Studio 6.0"">"
    HTML = HTML & "<title>HTMLMail</title>"
    HTML = HTML & "</head>"
    HTML = HTML & "<body bgcolor=""FFFFFF"">"
    HTML = HTML & "<IMG SRC=""http://www.microsoft.com/library/"
    HTML = HTML & "images/gifs/homepage/microsoft.gif"" BORDER=0 "
    HTML = HTML & "WIDTH=167 HEIGHT=36 ALT=""Microsoft Corporation"">"
    HTML = HTML & "<p><font size =""3"" face=""Arial""><strong>"
    HTML = HTML & "Microsoft Exchange CDONTS Example</strong></p>"
    HTML = HTML & "<p><font size =""2"" face=""Tahoma"">"
    HTML = HTML & "CDO for NTS allows an easy way to send mail.<br>"
    HTML = HTML & "This example shows how the content can be "
    HTML = HTML & "an HTML page<br>"
    HTML = HTML & "which allows you to send rich text and"
    HTML = HTML & "inline graphics.</p>"
    HTML = HTML & "</body>"
    HTML = HTML & "</html>"

    myMail.From="someone@microsoft.com"
    myMail.To="someone@microsoft.com"
    myMail.Subject="Sample CDONTS HTML Message"
    myMail.BodyFormat=0
    myMail.MailFormat=0
    myMail.Body=HTML
    myMail.Send
    set mymail=nothing
    Response.Write "Message Sent"
    %>
    </HEAD>
    <BODY>
    </BODY>
    </HTML>
				

Modification Type:MajorLast Reviewed:9/8/2005
Keywords:kbhowto kbhtml kbMsg KB189945