欢迎光临
我们一直在努力

ASP.NET结合COM组件发送Email-.NET教程,.NET Framework

建站超值云服务器,限时71元/月

在系统目录(如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();

}

  运行程序即可。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP.NET结合COM组件发送Email-.NET教程,.NET Framework
分享到: 更多 (0)

相关推荐

  • 暂无文章