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

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

点击次数:21 次 发布日期:2008-11-21 22:08:30 作者:源代码网
源代码网推荐

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;
}
}


}
}

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华