Microsoft KB Archive/310224

= How to use the Cdosys.dll library to process mail in the Drop directory by using Visual C# =

Article ID: 310224

Article Last Modified on 12/3/2007

-

APPLIES TO


 * Microsoft Visual C# 2005
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Collaboration Data Objects 2.0
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7
 * Microsoft Internet Information Services 6.0
 * Microsoft Internet Information Services 5.0

-



This article was previously published under Q310224



INTRODUCTION
This article describes how to use Microsoft Collaboration Data Objects (CDO) for Windows 2000 library (Cdosys.dll) to act on a message. This article describes how to act on a message in Microsoft Visual C# .NET or Microsoft Visual C# 2005. To act on a message, you can do any one of the following:
 * You can click Reply.
 * You can click Reply All.
 * You can click Forward.

Note The Cdosys.dll library is also known as CDOSYS.



MORE INFORMATION
To use CDOSYS to act on a message, follow these steps:  Start Microsoft Visual Studio .NET or Microsoft Visual C# 2005. On the File menu, click New, and then click Project. Click Console Application in the Visual C# Projects types list.

Note In Microsoft Visual C# 2005, click Console Application in the Visual C# 2005 list.

In Visual Studio .NET, Class1.cs is created by default. In Visual Studio 2005, Program.cs is created by default. Add a reference to the Microsoft CDO For Windows 2000 Library.

To do this, follow these steps:  On the Project menu, click Add Reference. On the COM tab, click Microsoft CDO For Windows 2000 Library, and then click Select.

Note In Visual Studio 2005, you do not have to click Select. In the Add References dialog box, click OK to accept your selections.

If you receive a message to generate wrappers for the libraries that you selected, click Yes.</li></ol> </li>  In the Code window, replace all the code with the following code: namespace CdoSys {   using System; class Class1 {       static void Main(string[] args) {           try {                          CDO.DropDirectory iDropDir = new CDO.DropDirectory; CDO.IMessages iMsgs; CDO.IMessage iMsgReply; CDO.IMessage iMsgReplyAll; CDO.IMessage iMsgForward;

// Get the messages from the Drop directory. iMsgs = iDropDir.GetMessages(&quot;C:\\Inetpub\\mailroot\\Drop&quot;); Console.WriteLine(&quot;Messages Count : &quot; + iMsgs.Count.ToString);

foreach (CDO.IMessage iMsg in iMsgs) {                   Console.WriteLine(iMsgs.get_FileName(iMsg));

// Output some common properties of the extracted message. Console.WriteLine(&quot;Subject: &quot; + iMsg.Subject); Console.WriteLine(&quot;TextBody: &quot; + iMsg.TextBody); Console.WriteLine(&quot;datereceived: &quot; + iMsg.Fields[&quot;urn:schemas:httpmail:datereceived&quot;].Value); Console.WriteLine(&quot;sendername: &quot; + iMsg.Fields[&quot;urn:schemas:httpmail:sendername&quot;].Value); Console.WriteLine(&quot;senderemail: &quot; + iMsg.Fields[&quot;urn:schemas:httpmail:senderemail&quot;].Value); Console.WriteLine(&quot;from: &quot; + iMsg.Fields[&quot;urn:schemas:httpmail:from&quot;].Value); Console.WriteLine(&quot;sender: &quot; + iMsg.Fields[&quot;urn:schemas:httpmail:sender&quot;].Value);

// Reply. iMsgReply = iMsg.Reply; // TODO: Change &quot;rhaddock@northwindtraders.com&quot; to your e-mail address. iMsgReply.From = &quot;rhaddock@northwindtraders.com&quot;; iMsgReply.TextBody = &quot;I agree. You can continue.&quot; + &quot;\n\n&quot; + iMsgReply.TextBody; iMsgReply.Send;

// This is ReplyAll. iMsgReplyAll = iMsg.ReplyAll;

// TODO: Change &quot;rhaddock@northwindtraders.com&quot; to your e-mail address. iMsgReplyAll.From = &quot;rhaddock@northwindtraders.com&quot;; iMsgReplyAll.TextBody = &quot;I agree. You can continue&quot; + &quot;\n\n&quot; + iMsgReplyAll.TextBody; iMsgReplyAll.Send;

// This is Forward. iMsgForward = iMsg.Forward; // TODO: Change &quot;rhaddock@northwindtraders.com&quot; to your e-mail address. iMsgForward.From = &quot;rhaddock@northwindtraders.com&quot;; // TODO: Change &quot;Jonathan@northwindtraders.com&quot; to the address that you want to forward to. iMsgForward.To = &quot;Jonathan@northwindtraders.com&quot;; iMsgForward.TextBody = &quot;You missed this.&quot; + &quot;\n\n&quot; + iMsgForward.TextBody; iMsgForward.Send; }

// Clean up memory. iMsgs = null; iMsgReply = null; iMsgReplyAll = null; iMsgForward = null; }           catch (Exception e)            { Console.WriteLine(&quot;{0} Exception caught.&quot;, e); }           return; }   } } </li> Where &quot;TODO:&quot; appears in the previous sample code, modify the code as indicated.</li> Press F5 to build and to run the program.</li></ol>

<div class="references_section">