首 页 | 新 闻 | 技术中心 | 第二书店 | 《程序员》 | 《开发高手》 | 社 区 | 黄 页 | 人 才
移 动专 题SUNIBM微 软微 创精 华Donews人 邮
我的技术中心 
我的分类 我的文档
全部文章 发表文章
专栏管理 使用说明



 RSS 订阅 
最新文档列表
Windows/.NET
.NET  (rss)    
Visual C++  (rss)    
Delphi  (rss)    
Visual Basic  (rss)    
ASP  (rss)    
JavaScript  (rss)    
Java/Linux
Java  (rss)    
Perl  (rss)    
综合
其他开发语言  (rss)    
文件格式  (rss)    
企业开发
游戏开发  (rss)    
网站制作技术  (rss)    
数据库
数据库开发  (rss)    
软件工程
其他  (rss)    

积极原创作者 
yjz0065 (115)
iiprogram (70)
ShowLong (2)
coofucoo (106)
psyl (153)
capsicum29 (8)
qdzx2008 (51)
cyp403 (16)
lphpc (31)
smallnest (63)
CSDN - 文档中心 - .NET 阅读:5415   评论: 4    参与评论
标题   使用System.Web.Mail通过需验证的邮件服务器发送邮件     选择自 zhzuo 的 Blog
关键字   使用System.Web.Mail通过需验证的邮件服务器发送邮件
出处  

使用System.Web.Mail通过需验证的邮件服务器发送邮件

 

使用System.Web.Mail通过需验证的邮件服务器发送邮件,下面是Scott WaterdotText中写的一个发邮件的类,使用起来比较方便,整个类的代码如下:

using System;

using System.Web.Mail;

 

namespace ZZ

{

     ///

     /// SystemMail 的摘要说明。

     ///

     public class SystemMail

     {

         private string _adminEmail;

         private string _smtpServer = "localhost";

         private string _password;

         private string _userName;

 

         public SystemMail()

         {            

         }

 

        

         public string AdminEmail

         {

              get{return _adminEmail;}

              set{_adminEmail = value;}

         }

 

        

         public string SmtpServer

         {

              get{return _smtpServer;}

              set{_smtpServer = value;}

         }

 

        

         public string Password

         {

              get{return _password;}

              set{_password = value;}

         }

 

        

         public string UserName

         {

              get{return _userName;}

              set{_userName = value;}

         }

 

         public bool Send(string to, string from, string subject, string message)

         {

              try

              {

                   MailMessage em = new MailMessage();

                   em.To = to;

                   em.From = from;

                   em.Subject = subject;

                   em.Body = message;

 

                   //Found out how to send authenticated email via System.Web.Mail at http://SystemWebMail.com (fact 3.8)

                   if(this.UserName != null && this.Password != null)

                   {

                       em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");   //basic authentication

                       em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", this.UserName); //set your username here

                       em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", this.Password); //set your password here

                   }

 

                   SmtpMail.SmtpServer = this.SmtpServer;

                   SmtpMail.Send(em);

                   return true;

              }

              catch

              {

                   return false;

              }

          }

 

     }

}

需要更多信息可以查看http://SystemWebMail.com

 

 


相关文章
对该文的评论
CSDN 网友 ( 2004-07-27)
原来如此 
CSDN 网友 ( 2004-07-26)
在.NET Framework 1.1 上才有Fields属性,1.0不支持。
CSDN 网友 ( 2004-07-15)
这是在.Net1.1版才新增的属性
连文件都还是空白的内容..= ="
CSDN 网友 ( 2004-07-15)
MailMessage 哪裏來的 Fields 屬性???
你用的2003???

我在2001上編譯都通不過。