协作数据对象 Windows 2000 协作数据对象 (CDOSYS) 是微软用来创建和发送基于标准的电子邮件信息的消息组件。它是 用与 Windows NT的协作数据对象(CDONTS) 的替代物。 尽管由于向后兼容的原因 CDONTS 已包含在 Windows 2000 中, 但是 Windows XP, Windows Server 2003 以及更高版本均未包含或支持 CDONTS 组件。 所以任何使用 CDONTS 发送消息的应用程序都必须迁移到使用 CDOSYS 上来。它提供了相同的功能,而且易于使用。
发送邮件示例代码 下面的 C# 示例代码将包含一个演示如何发送简单电子邮件的 Windows 控制台程序。当没有设置 SmtpMail 的 SmtpServer 属性时,本地机器将为其默认配置。你必须确保添加了针对 System.Web.dll 的引用,因为它是控制台应用程序而不是 ASP.NET 应用。
using System; using System.Web.Mail;
namespace CodeGuru.SendMail { /// <summary> /// Test console application to demonstrate sending e-mail. /// </summary> class TestMail { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { TestMail.Send("testuser@codeguru.com", "mstrawmyer@crowechizek.com",