C#使用CDO发送邮件的方法
本文实例讲述了C#使用CDO发送邮件的方法。分享给大家供大家参考。具体分析如下:
CDO是一个名为Microsoft CDO For Exchange 2000 Library的COM组件,我们可以用它来连接SMTP Server,使用用户名/密码验证发送邮件。
/** * C# Programmers Pocket Consultant * Author: Gregory S. MacBeth * Email: gmacbeth@comporium.net * Create Date: June 27, 2003 * Last Modified Date: * Version: 1 */ using System; using CDO; using ADODB; namespace Client.Chapter_19___Office_Integration { public class UsingCDOEx { static void Main(string[] args) { Message MyMessage = new MessageClass(); Configuration MyConfig = MyMessage.Configuration; Fields MyFields = MyConfig.Fields; MyFields[@"http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2; MyFields[@"http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = 25; MyFields[@"http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = "smarthost"; MyFields.Update(); MyMessage.Configuration = MyConfig; MyMessage.TextBody = "This is a test message"; MyMessage.Subject = "Testing"; MyMessage.From = "gregmcb@microsoft.com"; MyMessage.To = "pmacbeth@comporium.com"; MyMessage.Send(); } } }
希望本文所述对大家的C#程序设计有所帮助。
赞 (0)