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

Article translations Article translations
Article ID: 310233 - View products that this article applies to.
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
Expand all | Collapse all

On This Page

SUMMARY

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.

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["http://schemas.microsoft.com/cdo/configuration/urlproxyserver"];
    oField.Value = "itgproxy";
    
                oField = oFields["http://schemas.microsoft.com/cdo/configuration/proxyserverport"];
    oField.Value = 80;
    
                oField = 
    oFields["http://schemas.microsoft.com/cdo/configuration/smtpsserver"];
    oField.Value = "smarthost";			
    
                oField = 
    oFields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
    oField.Value =25;			 
    	
                oFields.Update();
    
                oMsg.Configuration = iConfg;
    
                // Set common properties for Message
                oMsg.Subject = "Test SMTP";
                oMsg.From = "from@microsoft.com";
                oMsg.To = "to@microsoft.com";
    
                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.

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web site:
Microsoft Office Development with Visual Studio
http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx

Properties

Article ID: 310233 - Last Review: November 29, 2007 - Revision: 4.2
APPLIES TO
  • 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
Keywords: 
kbhowtomaster KB310233

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com