You are currently offline, waiting for your internet to reconnect

HOW TO: Send Mail with Proxy Server That Is Configured Manually by Using Collaboration Data Objects for Windows in Visual C# .NET

This article was previously published under Q310233
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
This article describes how to use Microsoft Collaboration Data Objects (CDO) for Windows Library in Visual C# .NET to send an e-mail message with a proxy server that is configured manually.

back to the top

Send Mail with a Proxy Server That Is Configured Manually

  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. Click Visual C# Projects under Project Types, and then click Console Application under Templates. By default, Class1.cs is created.
  4. Add a reference to the Microsoft CDO for Windows 2000 Library and the Microsoft ActiveX Data Objects 2.x Library. To do this, follow these steps:
    1. On the Project menu, click Add Reference.
    2. Click the COM tab.
    3. Click Microsoft CDO for Windows 2000 Library, and then click Select.
    4. Click Microsoft ActiveX Data Objects 2.x Library, and then click Select.
    5. Click OK. If you are prompted to generate wrappers for the libraries that you selected, click Yes.
  5. In the Code window, replace the default code with the following code:
    namespace CdoSys{    using System;    class Class1    {        static void Main(string[] args)        {            try             {			            CDO.Message oMsg = new CDO.Message();            CDO.Configuration iConfg = new CDO.Configuration();            ADODB.Fields oFields;            ADODB.Field oField;            oFields = iConfg.Fields;            // Set Proxy properties			            oField = oFields[""];oField.Value = "itgproxy";            oField = oFields[""];oField.Value = 80;            oField = oFields[""];oField.Value = "smarthost";			            oField = oFields[""];oField.Value =25;			 	            oFields.Update();            oMsg.Configuration = iConfg;            // Set common properties for Message            oMsg.Subject = "Test SMTP";            oMsg.From = "";            oMsg.To = "";            oMsg.Send();            }            catch (Exception e)            {                Console.WriteLine("{0} Exception caught.", e);            }            return;        }    }}					
  6. Modify the code where you see the TODO comments.
  7. Press F5 to build and to run the application.
  8. Verify that the e-mail message is sent and received.
back to the top
For more information, visit the following Microsoft Developer Network (MSDN) Web site:
Microsoft Office Development with Visual Studio
back to the top

Article ID: 310233 - Last Review: 11/29/2007 17:17:15 - Revision: 4.2

Microsoft Collaboration Data Objects 2.0, Microsoft Visual C# .NET 2002 Standard Edition, Microsoft ActiveX Data Objects 2.5, Microsoft ActiveX Data Objects 2.6, Microsoft ActiveX Data Objects 2.7

  • kbhowtomaster KB310233