How to send HTML formatted mail using CDO for Windows 2000 and a remote SMTP service

Retired KB Content Disclaimer

This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Summary

This article describes how to send HTML formatted mail using CDO for Windows 2000 (CDOSYS) or CDO for Exchange 2000 (CDOEX) using a remote computer's SMTP service.

More Information

  1. Create a file called Cdosmtp.vbs and paste the following code:
    ' Send by connecting to port 25 of the SMTP server.
    Dim iMsg
    Dim iConf
    Dim Flds
    Dim strHTML

    Const cdoSendUsingPort = 2

    set iMsg = CreateObject("CDO.Message")
    set iConf = CreateObject("CDO.Configuration")

    Set Flds = iConf.Fields

    ' Set the CDOSYS configuration fields to use port 25 on the SMTP server.

    With Flds
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
    'ToDo: Enter name or IP address of remote SMTP server.
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "<remote SMTP server>"
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
    .Update
    End With

    ' Build HTML for message body.
    strHTML = "<HTML>"
    strHTML = strHTML & "<HEAD>"
    strHTML = strHTML & "<BODY>"
    strHTML = strHTML & "<b> This is the test HTML message body</b></br>"
    strHTML = strHTML & "</BODY>"
    strHTML = strHTML & "</HTML>"

    ' Apply the settings to the message.
    With iMsg
    Set .Configuration = iConf
    .To = "<email address>" 'ToDo: Enter a valid email address.
    .From = "<email address>" 'ToDo: Enter a valid email address.
    .Subject = "This is a test CDOSYS message (Sent via Port 25)"
    .HTMLBody = strHTML
    .Send
    End With

    ' Clean up variables.
    Set iMsg = Nothing
    Set iConf = Nothing
    Set Flds = Nothing

    MsgBox "Mail Sent!"
  2. Edit the sections of the code that are marked "ToDo".
  3. Save the file, and then double-click it.

    The code creates an HTML-formatted message and sends it using the remote computer's SMTP service.

References

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
286430 How To Send HTML Formatted mail Using CDO for Windows 2000 and the Local Pickup Directory
Properties

Article ID: 286431 - Last Review: Jun 19, 2014 - Revision: 1

Feedback