Microsoft KB Archive/313773

= How to send e-mail messages by using CDOSYS and the local SMTP directory with Visual Basic .NET =

Article ID: 313773

Article Last Modified on 11/29/2007

-

APPLIES TO


 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Collaboration Data Objects 2.0

-



This article was previously published under Q313773



Caution ADO and ADO MD have not been fully tested in a Microsoft .NET Framework environment. They may cause intermittent issues, especially in service-based applications or in multithreaded applications. The techniques that are discussed in this article should only be used as a temporary measure during migration to ADO.NET. You should only use these techniques after you have conducted complete testing to make sure that there are no compatibility issues. Any issues that are caused by using ADO or ADO MD in this manner are unsupported. For more information, see the following article in the Microsoft Knowledge Base:

840667 You receive unexpected errors when using ADO and ADO MD in a .NET Framework application



SUMMARY
This article describes how to use the Collaboration Data Objects (CDO) for Microsoft Windows 2000 library and the local SMTP directory to send an HTML e-mail message by using Microsoft Visual Basic .NET. You must run this sample on a server that has an SMTP service running to send the e-mail message.



MORE INFORMATION
 Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click Project. Under Project Types, click Visual Basic Projects. Under Templates, click Console Application, and then click OK.

By default, Module1.vb is created. Add a reference to the Microsoft CDO for Windows 2000 library. To do this, follow these steps:  On the Project menu, click Add Reference.</li> On the COM tab, click Microsoft CDO For Windows 2000 Library, and then click Select.</li> In the Add References dialog box, click OK to accept your selections. If you receive a prompt to generate wrappers for the libraries that you selected, click Yes.</li></ol> </li> Follow steps 5a through 5c to add a reference to the Microsoft ActiveX Data Objects 2.5 library.</li>  In the code window, replace all the code with: Imports System.Reflection

Module Module1

Sub Main Dim oMsg As CDO.Message = New CDO.Message oMsg.From = &quot;from@microsoft.com&quot; oMsg.To = &quot;to@microsoft.com&quot; oMsg.Subject = &quot;CdoSys HTML mail in VB.NET (pickup)&quot;

Dim sHtml As String sHtml = &quot;<HTML>&quot; & _ &quot;<HEAD>&quot; & _ &quot;<TITLE>Simple CDOSYS Message</TITLE>&quot; & _ &quot;</HEAD>&quot; & _ &quot;<BODY><P>&quot; & _ &quot; <Font Color=Green>Simple CDOSYS HTML Message</Font> &quot; & _ &quot;</BODY>&quot; & _ &quot;</HTML>&quot;

oMsg.HTMLBody = sHtml

' Set configuration. Dim iConfg As CDO.Configuration = New CDO.Configuration

Dim oFields As ADODB.Fields oFields = iConfg.Fields

Dim oField As ADODB.Field oField = oFields(&quot;http://schemas.microsoft.com/cdo/configuration/sendusing&quot;) oField.Value = 1  ' Sets the configuration to use the local SMTP server.

oFields.Update oMsg.Configuration = iConfg

oMsg.Send

oMsg = Nothing iConfg = Nothing oFields = Nothing oField = Nothing End Sub

End Module </li> Search for &quot;TODO&quot; in the code, and then modify the code for your environment.</li> Press F5 to build and to run the program.</li> Verify that the e-mail message has been sent and received.</li></ol>

Additional query words: send mail CDOSYS Local SMTP Directory

Keywords: kbmsg kbcode kbxml kbhowtomaster KB313773

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.