.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
解决.NET平台邮件发送CDO.Message错误

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

喜欢上C#,再也没有理由离开它去学另一种语言,asp中可以方便的调用CDO并附上账号和密码来发送邮件,但System.Web.Mail命名空间里却并未让我等到输入用户名和密码的属性,在观看了别的同仁的文章,试了一个果然见效,在此与大家分享一下。
由于在.NET平台上并不在于程序写多少,更不在于用什么语言去表达,重要的似乎是思想,所以我喜欢C#也只用C#写这几句代码吧,VB.NET与J#的朋友可以稍微改一下即可用了......
private static int GoToSendMail(string Body,string To)
  {
   try
   {
    System.Web.Mail.MailMessage mm=new System.Web.Mail.MailMessage();
    mm.BodyFormat=System.Web.Mail.MailFormat.Html;
    mm.From="[email protected]";
    mm.To=To;
    mm.BodyEncoding=System.Text.Encoding.GetEncoding(936);
    mm.Subject="您好!我是梦猫.NET工作室希望与您携手一起成长。";
    mm.Body=Body;
    mm.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
    mm.Fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"] = "[email protected]";//发送地址;如果mm.From写了这儿可以不写这句
    mm.Fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"] = "[email protected]";
    mm.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "XXX";//验证账号:发送者邮箱账号
    mm.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "XXX"; //验证密码:发送者邮箱密码
    mm.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1; //验证级别0,1,2
    mm.Fields["http://schemas.microsoft.com/cdo/configuration/languagecode"] = 0x0804;//语言代码
    mm.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = "SMTP.XXX.com"; //SMTP Server
    System.Web.Mail.SmtpMail.SmtpServer="SMTP.XXX.com";//上句和这句重着,这句可以替代上句
    System.Web.Mail.SmtpMail.Send(mm);
    return 0;
   }
   catch(System.Exception e)
   {
    Response.Write(e.Message+e.StackTrace+e.Source);
    return -1;
   }
  }
本程序在XP和2000Server IIS6上均通过


相关文章

相关软件