ASP.NET结合COM组件发送Email (转)

ASP.NET结合COM组件发送Email (转)[@more@]

ASP.NET结合COM组件发送EMail

阿好空间
http://www.cnblogs.com/hbzxf

  在开发电子邮件发送程序的时候,我们经常需要使用到相应的组件,其实不需要第三方的组件(例如:jmail)照常可以做到发送email的功能。

  在系统目录(如c:winnt或c:windows)的system32子目录中可以找到一个名称为cdosys.dll的文件,我们可以通过ASP.net调用此COM组件来实现Email的发送。cdosys构建在SMTP协议和NNTP协议之上,并且作为Windows2000 Server的组件被安装,当然我们也可以使用Exchange2000中cdoex.dll来实现发送邮件的机制。由于cdosys.dll自动内嵌到了操作系统中,所以不用再去注册相应的其他发送程序,下面我们来做一个发送实例。

  1、新建一个项目文件

  2、添加引用系统目录下的cdosys.dll文件,在引用中会发现添加了两个要用到的接口:CDO,ADOdb

  3、添加新项文件sendmail.aspx,在其页面上放置三个Label,三个Textbox,作用分别为收件人地址、主题、内容,放置一个Button按钮。

  4、切换到代码页,创建一下内容

 public void CDOsendmail()
 {
 try
 {
 CDO.Message Msg = new CDO.Message();
 Msg.From = "rattlesnake@263.net";
 Msg.To = this.TextBox1.Text.Trim();
 Msg.Subject = this.TextBox2.Text.Trim();
 Msg.HTMLBody = "

"+this.TextBox3.Text
+"";
 CDO.IConfiguration Config = Msg.Configuration;
 ADODB.Fields oFields = Config.Fields;
 oFields[" microsoft.com/cdo/configuration/sendusing"].Value'>http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2;
 oFields[" http://schemas.microsoft.com/cdo/configuration/sendusername"].Value="rattlesnake";
 oFields[" word"].Value'>http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value="pass";
 oFields[" http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value=1;
 oFields[" http://schemas.microsoft.com/cdo/configuration/languagecode"].Value=0x0804;
 oFields[" http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value="smtp.263.net";
 oFields.Update();

 Msg.BodyPart.Charset = "gb2312";
 Msg.HTMLBodyPart.Charset = "gb2312";


 Msg.Send();
 Msg = null;
 }
 catch(Exception err)
 {
  throw err;
 }
 }

  5、为Button添加Click事件

 private void Button1_Click(object sender, System.EventArgs e)
 {
  this.CDOsendmail();
 }

  运行程序,然后检查邮箱即可。


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752019/viewspace-982293/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10752019/viewspace-982293/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值