Microsoft KB Archive/313776

= How to send mail with configuration by using Collaboration Data Objects for Windows Library in Visual Basic .NET =

Article ID: 313776

Article Last Modified on 11/29/2007

-

APPLIES TO


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

-



This article was previously published under Q313776





For a Microsoft Visual Basic 6.0 version of this article, see 161833.

IN THIS TASK
SUMMARY
 * Create a sample to send an e-mail message with configuration

REFERENCES



SUMMARY
This step-by-step article describes how to use Microsoft Collaboration Data Objects (CDO) for Windows Library to send an e-mail message in Visual Basic .NET.

back to the top

Create a sample to send an e-mail message with configuration
 Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click Project. Click Visual Basic Projects under Project Types, and then click Console Application under Templates. By default, Module1.vb is created. Add a reference to the Microsoft CDO for Windows 2000 Library and the Microsoft ActiveX Data Objects 2.5 Library. To do this, follow these steps:  On the Project menu, click Add Reference. Click the COM tab.</li> Click Microsoft CDO for Windows 2000 Library, and then click Select.</li> Click Microsoft ActiveX Data Objects 2.5 Library, and then click Select.</li> Click OK. If you are prompted to generate wrappers for the libraries that you selected, click Yes.</li></ol> </li>  In the Code window, replace the default code with the following code: Imports System.Reflection

Module Module1

Sub Main Dim oMsg As CDO.Message = New CDO.Message Dim iConfg As CDO.Configuration Dim oFields As ADODB.Fields Dim oField As ADODB.Field iConfg = oMsg.Configuration oFields = iConfg.Fields

oField = oFields(&quot;http://schemas.microsoft.com/cdo/configuration/sendusing&quot;) oField.Value = 2  ' CDO.CdoConfiguration.cdoSMTPServer

oField = oFields(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserver&quot;) oField.Value = &quot;smarthost&quot; ' TODO:

oFields.Update oMsg.Configuration = iConfg

oMsg.TextBody = &quot;Hello, how are you doing?&quot; oMsg.Subject = &quot;Test SMTP&quot; oMsg.From = &quot;from@microsoft.com&quot;  ' TODO: oMsg.To = &quot;to@microsoft.com&quot;      ' TODO:

oMsg.Send

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

End Module </li> Modify the code where you see the TODO comments.</li> Press F5 to build and to run the application.</li> Verify that the e-mail message is sent and received.</li></ol>

back to the top

<div class="references_section">