asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Sending HTML with CDO
By Alan Saldanha
Rating: 3.8 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Introduction

    IIS 4.0 provides an interface to send e-mail via SMTP or the Exchange Server. This interface is called CDO and can be used from an Active Server Page. In March, we published an article by Jon Whiting that outlines the basics of sending e-mail with CDO, entitled: "Collaboration Data Object and IIS 4.0".

    In addition to sending plain text mail, you can use the CDO object to send MIME HTML messages and attachments using the AttachURL method. Using AttachURL, you can send e-mail that looks, in Outlook Express, like Figure 1.

    Figure 1 : MIME HTML E-mail in Outlook Express
    Click Here to View Figure

    When you click on "Apr 8, 1998 - New Vendor Site", Internet Explorer will open and navigate to the page indicated in the link. Figure 2 shows the browser after following the link from Figure 1.

    Figure 2 : Internet Explorer
    Click Here to View Figure

    Sending HTML E-mail

    The following snippet of script was used to send the e-mail message in Figure 1.

    
    <%
    Dim myMail 
    Set myMail = CreateObject("CDONTS.NewMail") 
    myMail.AttachURL "c:\images\logo.gif", "logo.gif" 
    myMail.AttachURL "c:\images\new.gif", "new.gif" 
     
    HTML = "<!DOCTYPE HTML PUBLIC ""-//IETF//DTD HTML//EN"">" & NL 
    HTML = HTML & "<html>" 
    HTML = HTML & "<head>" 
    HTML = HTML & "<meta http-equiv=""Content-Type""" 
    HTML = HTML & "content=""text/html; charset=iso-8859-1"">" 
    HTML = HTML & "<title>15 Seconds</title>" 
    HTML = HTML & "</head>" 
    HTML = HTML & "<body bgcolor=""#FFFFFF"">" 
    HTML = HTML & "<p><font  face=""Arial Black""><strong>" 
    HTML = HTML & "<img src=logo.gif><br>" 
    HTML = HTML & "<img src=new.gif>"
    HTML = HTML & "<a href=http://vendors.15seconds.com>"
    HTML = HTML & "Apr 8, 1998 - New Vendor Site</a>" 
    HTML = HTML & "</strong></font></p>" 
    HTML = HTML & "<p>15 Seconds is proud to announce a new site"
    HTML = HTML & "dedicated to component vendors. The 15 Seconds'"
    HTML = HTML & "Vendor Site will help vendors, design, develop and"
    HTML = HTML & "marketing their Active Server components. The"
    HTML = HTML & "premier article for the new vendor site is entitled:"
    HTML = HTML & """Twelve Steps to Becoming a Component Vendor.""" 
    
    HTML = HTML & "</body>" 
    HTML = HTML & "</html>" 
     
    myMail.From = "alan@vallin.com" 
    myMail.To = "alan@vallin.com" 
    myMail.Subject = "15 Seconds Update" 
    myMail.BodyFormat = 0 
    myMail.MailFormat = 0 
    myMail.Body = HTML 
    myMail.Send 
    %>
    
    

    Using Images

    A directory was used to hold the images. In the script, the directory images (c:\images) was used to store the images (logo.gif and new.gif). You must know the physical path of the images on the web server. When the e-mail is sent, the images are also sent with the e-mail.

    To attach the images in the e-mail you need use the AttachURL method of the CDO object. The actual path of an image was referenced in the AttachURL method. For example in:

    
    myMail.AttachURL  "c:\images\logo.gif", "logo.gif" 
    
    
    logo.gif refers to the image at c:\images\logo.gif. The alias, in this case “logo.gif”, is used throughout the rest of the HTML page as illustrated by:

    
    HTML = HTML & "<img src=logo.gif><br>"  
    
    

    Including HTML

    The body of an e-mail message can contain either plain text or HTML. The BodyFormat property specifies whether or not any HTML is included. If BodyFormat is set to 0, the Body property of the CDO object can include HTML. If set to 1, it can contain only plain text. In the script, the BodyFormat is set to 0:

    
    myMail.BodyFormat = 0
    
    
    An e-mail message can be plain text or in MIME format. The MailFormat property needs to be set to 0 for MIME format or 1 for plain text. In the script, the MailFormat is set to 0:

    
    MyMail.MailFormat = 0
    
    

    Conclusion

    It is important to understand that not all e-mail clients display HTML e-mail messages. The HTML e-mail works just great with Microsoft’s Outlook Express. However, the images were not displayed when the e-mail was read using Netscape’s Communicator.

    The CDO object has a lot to offer if you are looking to develop HTML-based e-mail. Combined with Server Object’s ASPImage and ASPChart you could send customized e-mail with personalized graphics to every subscriber to your Web site or every employee, in the case of an intranet.

    Additional Resources

    Collaboration Data Object and IIS 4.0

    Additional Articles by Alan

    ASP On Speed
    How To Track User Activity At A Web Site Using ASP
    ASP 101 – A Database Interfacing Primer

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info

    Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers