本文將告訴您,如何使用 Windows 2000 程式庫 (Cdosys.dll) 的 Microsoft 共同作業資料物件 (CDO),可在訊息上動作。本文將告訴您,如何在 Microsoft Visual C#.NET 或 Microsoft Visual C# 2005年中的訊息上動作。 若要在訊息上動作,您可以執行下列其中一項動作:
- 您可以按一下 [回覆]。
- 您可以按一下 [全部回覆]。
- 您可以按一下 [轉寄。
附註Cdosys.dll 程式庫也稱為是 CDOSYS。
如果要使用 CDOSYS 訊息上作用,請依照下列步驟執行:
- 啟動 Microsoft Visual Studio.NET 或 Microsoft Visual C# 2005 。
- 在 [檔案] 功能表上按一下 [新增],然後按一下 [專案]。
- 按一下 [Visual C# 專案類型] 清單中的 [主控台應用程式]。
附註 2005 年 Microsoft Visual C# 按一下 [Visual C# 2005年] 清單中的 [主控台應用程式]。
在 Visual 的 Studio.NET Class1.cs 建立根據預設值。在 Visual 的 Studio 2005 中預設會建立 Program.cs。 - 加入 Microsoft CDO 對於 Windows 2000 庫 的參考。
要這麼做,請您執行下列步驟:- 在 [專案] 功能表上按一下 [加入參考]。
- 在 [COM] 索引標籤上按一下 Microsoft CDO 對於 Windows 2000 櫃,然後按一下 [選取]。
附註在 Visual 的 Studio 2005 中並不需要按一下 [選取。 - 在 [加入參考] 對話方塊中,按一下 [確定] 以接受您的選擇。
如果您收到一則訊息,以產生您所選取的程式庫的包裝函式,按一下 [是]。
- 在程式碼] 視窗以下列程式碼取代所有程式碼:
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("C:\\Inetpub\\mailroot\\Drop");
Console.WriteLine("Messages Count : " + 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("Subject: " + iMsg.Subject);
Console.WriteLine("TextBody: " + iMsg.TextBody);
Console.WriteLine("datereceived: " + iMsg.Fields["urn:schemas:httpmail:datereceived"].Value);
Console.WriteLine("sendername: " + iMsg.Fields["urn:schemas:httpmail:sendername"].Value);
Console.WriteLine("senderemail: " + iMsg.Fields["urn:schemas:httpmail:senderemail"].Value);
Console.WriteLine("from: " + iMsg.Fields["urn:schemas:httpmail:from"].Value);
Console.WriteLine("sender: " + iMsg.Fields["urn:schemas:httpmail:sender"].Value);
// Reply.
iMsgReply = iMsg.Reply();
// TODO: Change "rhaddock@northwindtraders.com" to your e-mail address.
iMsgReply.From = "rhaddock@northwindtraders.com";
iMsgReply.TextBody = "I agree. You can continue." + "\n\n" + iMsgReply.TextBody;
iMsgReply.Send();
// This is ReplyAll.
iMsgReplyAll = iMsg.ReplyAll();
// TODO: Change "rhaddock@northwindtraders.com" to your e-mail address.
iMsgReplyAll.From = "rhaddock@northwindtraders.com";
iMsgReplyAll.TextBody = "I agree. You can continue" + "\n\n" + iMsgReplyAll.TextBody;
iMsgReplyAll.Send();
// This is Forward.
iMsgForward = iMsg.Forward();
// TODO: Change "rhaddock@northwindtraders.com" to your e-mail address.
iMsgForward.From = "rhaddock@northwindtraders.com";
// TODO: Change "Jonathan@northwindtraders.com" to the address that you want to forward to.
iMsgForward.To = "Jonathan@northwindtraders.com";
iMsgForward.TextBody = "You missed this." + "\n\n" + iMsgForward.TextBody;
iMsgForward.Send();
}
// Clean up memory.
iMsgs = null;
iMsgReply = null;
iMsgReplyAll = null;
iMsgForward = null;
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
return;
}
}
} 。 - 其中"TODO:"會出現前一個範例程式碼中修改程式碼的指示。
- 按下 F5 以建置並執行程式。
取得更多資訊有關 Microsoft Office 開發與 Visual Studio 請造訪下列 Microsoft 開發 o 人 h 員 ? 工 u 具 ? 網路 (MSDN) 網站]:
如需有關如何使用 CDOSYS 的詳細資訊,按一下 [下列面的文件編號,檢視 「 Microsoft 知識庫 」 中 「 文件]:
310221?
(http://support.microsoft.com/kb/310221/
)
如何使用 Cdosys.dll 文件庫,藉由使用 Visual C#.NET 中嵌入一封新郵件的訊息
310225?
(http://support.microsoft.com/kb/310225/
)
如何使用 Cdosys.dll 文件庫,使用 Visual C#.NET,將訊息儲存至檔案
310212?
(http://support.microsoft.com/kb/310212/
)
如何使用 Cdosys.dll 文件庫來傳送電子郵件與附件
這篇文章中的資訊適用於:
- Microsoft Visual C# 2005
- Microsoft Visual C# .NET 2003 標準版
- 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
| kbmt kbsample kbcode kbhowto KB310224 KbMtzh |
機器翻譯重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:
310224?
(http://support.microsoft.com/kb/310224/en-us/
)
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。