动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   .Net → 阅读文章

 ASP.NET结合COM组件发送Email

作者来源: 
阅读 数 334 人次 , 2006-3-29 4:33:00 


  在系统目录(如c:\winnt或c:\windows)的system32子目录中可以找到一个名称为cdosys.dll的文件,我们可以通过asp.net调用此com组件来实现email的发送。cdosys构建在smtp协议和nntp协议之上,并且作为windows2000 server的组件被安装,当然我们也可以使用exchange2000中cdoex.dll来实现发送邮件的机制,由于cdosys.dll内嵌到了操作系统中,所以不用再去注册相应的其他邮件发送程序比如jmail等。

  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 = "<html><body>"+this.textbox3.text+"</body></html>";
  cdo.iconfiguration config = msg.configuration;
  adodb.fields ofields = config.fields;
  ofields["http://schemas.microsoft.com/cdo/configuration/sendusing"].value = 2;
 ofields["http://schemas.microsoft.com/cdo/configuration/sendusername"].value="rattlesnake";
 ofields["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();
}

  运行程序即可。


 本文Tags组件  C#  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:创建基于ASP.NET的SMTP邮件服务
· 下一篇:在ASP.NET下实现数字和字符相混合的验证码
· 用.NET创建定时缓存
· OLE DB 简介
· .net 里面 protected private 的变量也可以访问
· Java和ASP的交互(二)
· 我认为JSP有问题(下)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077