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



The information in this article applies to:

  • Microsoft Collaboration Data Objects for Windows 2000
  • Microsoft Visual C# .NET (2002)
  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 2.6
  • ActiveX Data Objects (ADO) 2.7

This article was previously published under Q310233

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.

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["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.
back to the top

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web site:

Microsoft Office Development with Visual Studio
http://msdn.microsoft.com/library/en-us/dnoxpta/html/vsofficedev.asp

back to the top

Modification Type:MajorLast Reviewed:1/19/2006
Keywords:kbHOWTOmaster KB310233 kbAudDeveloper