引用CDO组件,SYSTEM32下的CDOSYS。DLL,增加一个包装器
using CDO;
//本例使用CDO来实现发送邮件,可带验证,此示例在活动目录内向外网发送邮件成功 profession2k office2k office2k3下通过 VS2,2,VS2k3,要引用CDOSYS
Configuration conf=new Configuration();
//以下部分设置参数(服务器,端号,用户名,密码,发送邮件帐号,回复邮箱帐号)
conf.Fields[CdoConfiguration.cdoSendUsingMethod].Value=CdoSendUsing.cdoSendUsingPort;
conf.Fields[CdoConfiguration.cdoSMTPServer].Value="smtp.21cn.com";
conf.Fields[CdoConfiguration.cdoSMTPServerPort].Value=25;
conf.Fields[CdoConfiguration.cdoSMTPAccountName].Value="greystar@21cn.com";
conf.Fields[CdoConfiguration.cdoSendUserReplyEmailAddress].Value="/"greystar/" <Greystar@skyregister.com>";
conf.Fields[CdoConfiguration.cdoSendEmailAddress].Value="/"greystar/" <greystar@21cn.com>";
conf.Fields[CdoConfiguration.cdoSMTPAuthenticate].Value=CdoProtocolsAuthentication.cdoBasic;
conf.Fields[CdoConfiguration.cdoSendUserName].Value="greystar@21cn.com";
conf.Fields[CdoConfiguration.cdoSendPassword].Value="XXXXXXX";
conf.Fields.Update();
MessageClass msg=new MessageClass();
msg.Configuration=conf;
msg.To="greystar@21cn.com";
msg.Subject= "注册确认通知";
msg.HTMLBody="注册信息"
msg.From="greystar@21cn.com";
msg.Send();