当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 一个通过web.Mail发送邮件的类

ASP.NET
GridView添加删除按钮终极办法
AjaxPro让.NET的AjaxPro变得简单
c# 实现Word联接Excel的MailMerge功能
解开Ajax技术中的达芬奇密码
专家讲解用.NET编写串口程序的一点心得
利用AJAX和ASP.NET实现简单聊天室
如何快速捕获.NET代码中隐藏的BUG
动态网页原理/.net面面观
从N层到.NET详细剖析原理(2)
从N层到.NET详细剖析原理(1)
ASP.NET效率陷阱之——Attributes
在ASP.NET 2.0中建立站点导航层次(5)
在ASP.NET 2.0中建立站点导航层次(4)
在ASP.NET 2.0中建立站点导航层次(3)
在ASP.NET 2.0中建立站点导航层次(2)
在ASP.NET 2.0中建立站点导航层次(1)
动态网站Web开发PHP、ASP还是ASP.NET(2)
动态网站Web开发PHP、ASP还是ASP.NET(1)
让Apache支持ASP.NET-Apache,ASP.NET
.Net下的数据备份和还原

ASP.NET 中的 一个通过web.Mail发送邮件的类


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 84 ::
收藏到网摘: n/a

usingSystem;
usingSystem.Web;
usingSystem.Web.Mail;
usingDottext.Framework;
usingDottext.Framework.Configuration;

namespaceYourNamespace.Email
{
///<summary>
///DefaultimplementationoftheIMailProvider
///</summary>
publicclassSystemMail:IMailProvider
{
publicSystemMail(){}

#region
privatestring_to;
publicstringTo
{
get{return_to;}
set{_to=value;}
}

privatestring_from;
publicstringFrom
{
get{return_from;}
set{_from=value;}
}

privatestring_subject;
publicstringSubject
{
get{return_subject;}
set{_subject=value;}
}

privatestring_body;
publicstringBody
{
get{return_body;}
set{_body=value;}
}
#endregion

privatestring_adminEmail;
publicstringAdminEmail
{
get{return_adminEmail;}
set{_adminEmail=value;}
}

privatestring_smtpServer="localhost";
publicstringSmtpServer
{
get{return_smtpServer;}
set{_smtpServer=value;}
}

privatestring_password;
publicstringPassword
{
get{return_password;}
set{_password=value;}
}

privatestring_userName;
publicstringUserName
{
get{return_userName;}
set{_userName=value;}
}

publicboolSend(stringto,stringfrom,stringsubject,stringmessage)
{
try
{
MailMessageem=newMailMessage();
em.To=to;
em.From=from;
em.Subject=subject;
em.Body=message;

//FoundouthowtosendauthenticatedemailviaSystem.Web.Mailathttp://SystemWebMail.com(fact3.8)
if(this.UserName!=null&&this.Password!=null)
{
em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1");//basicauthentication
em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",this.UserName);//setyourusernamehere
em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",this.Password);//setyourpasswordhere

}

SmtpMail.SmtpServer=this.SmtpServer;
SmtpMail.Send(em);

returntrue;
}
catch
{
returnfalse;
}
}


}
}