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

本文介绍了一个基于System.Web.Mail的邮件发送实现方案。通过创建SystemMail类来封装邮件发送的功能,包括设置邮件的发件人、收件人、主题、正文及SMTP服务器等属性,并实现了发送认证邮件的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值