Microsoft KB Archive/286431

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

Article ID: 286431

Article Last Modified on 8/25/2005

-

APPLIES TO


 * Microsoft Collaboration Data Objects 2.0
 * Collaboration Data Objects for Exchange 2000

-



This article was previously published under Q286431



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
  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(&quot;CDO.Message&quot;) set iConf = CreateObject(&quot;CDO.Configuration&quot;)

Set Flds = iConf.Fields

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

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

' Build HTML for message body. strHTML = &quot;&quot; strHTML = strHTML & &quot;&quot; strHTML = strHTML & &quot;&quot; strHTML = strHTML & &quot; This is the test HTML message body &quot; strHTML = strHTML & &quot;&quot; strHTML = strHTML & &quot;&quot;

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

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

MsgBox &quot;Mail Sent!&quot;  Edit the sections of the code that are marked &quot;ToDo&quot;. 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.</ol>

<div class="references_section">