Microsoft KB Archive/313775

= How to use the CDOSYS Library to send an e-mail message by using the SMTP port in Visual Basic .NET =

Article ID: 313775

Article Last Modified on 11/29/2007

-

APPLIES TO


 * Microsoft ActiveX Data Objects 2.5
 * 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 Q313775



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 Windows 2000 (CDOSYS) Library to send an e-mail message by using the Simple Mail Transfer Protocol (SMTP) port in Microsoft Visual Basic .NET.



MORE INFORMATION
To send an e-mail message by using the SMTP port, follow these steps:  Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click Project. In the Visual Basic Projects types list, click Console Application.

By default, the Module1.vb file is created. Add a reference to the Microsoft CDO For Windows 2000 Library. To do so, follow these steps:  On the Project menu, click Add Reference. Click the COM tab, locate Microsoft CDO For Windows 2000 Library, and then click Select.</li> In the Add References dialog box, click OK.</li> If you are prompted to generate wrappers for the libraries that you selected, click Yes.</li></ol> </li> Repeat step 4 to add a reference to the Microsoft ActiveX Data Objects 2.5 Library.</li>  In the code window, replace the code with the following: 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 = CDO.CdoSendUsing.cdoSendUsingPort

' TODO: Replace with the port that you want to use. It must be the same ' port that the SMTP server is using. oField = oFields(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserverport&quot;) oField.Value = 25

' TODO: Replace with your SMTP server. oField = oFields(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserver&quot;) oField.Value = &quot;<SMTP Server>&quot;

oFields.Update oMsg.Configuration = iConfg

oMsg.TextBody = &quot;Test message body.&quot; oMsg.Subject = &quot;Test SMTP Message Send using port&quot; oMsg.From = &quot;from@example.com&quot; oMsg.To = &quot;to@example.com&quot;

oMsg.Send

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

End Module </li> Search for TODO in the code, and then modify the code for your environment.</li> Press F5 to build and to run the program.</li> Make sure that the e-mail message was sent and was received.</li></ol>

Additional query words: send mail CDOSYS SMTP Port

Keywords: kbhowto kbcode kbxml kbmsg KB313775

-

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

© Microsoft Corporation. All rights reserved.