How to send mail with configuration by using Collaboration Data Objects for Windows Library in Visual Basic .NET (313776)
The information in this article applies to:
- Microsoft Collaboration Data Objects for Windows 2000
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
This article was previously published under Q313776
For a Microsoft Visual Basic 6.0 version of this article, see 161833.
IN THIS TASKSUMMARY 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.
- Click Microsoft CDO for Windows 2000
Library, and then click Select.
- Click Microsoft ActiveX Data Objects 2.5
Library, and then click Select.
- Click OK. If you are prompted to generate wrappers for the libraries that
you selected, click Yes.
- 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("http://schemas.microsoft.com/cdo/configuration/sendusing")
oField.Value = 2 ' CDO.CdoConfiguration.cdoSMTPServer
oField = oFields("http://schemas.microsoft.com/cdo/configuration/smtpserver")
oField.Value = "smarthost" ' TODO:
oFields.Update()
oMsg.Configuration = iConfg
oMsg.TextBody = "Hello, how are you doing?"
oMsg.Subject = "Test SMTP"
oMsg.From = "from@microsoft.com" ' TODO:
oMsg.To = "to@microsoft.com" ' TODO:
oMsg.Send()
oMsg = Nothing
iConfg = Nothing
oFields = Nothing
oField = Nothing
End Sub
End Module
- Modify the code where you see the TODO comments.
- Press F5 to build and to run the application.
- Verify that the e-mail message is sent and
received.
back to the top
REFERENCES For more information, visit the following Microsoft
Developer Network (MSDN) Web site:
back to the top
Modification Type: | Major | Last Reviewed: | 9/8/2005 |
---|
Keywords: | kbHOWTOmaster KB313776 kbAudDeveloper |
---|
|