使用System.Web.Mail通过需验证的邮件服务器发送邮件
2024-07-21 02:24:36
供稿:网友
使用system.web.mail通过需验证的邮件服务器发送邮件
使用system.web.mail通过需验证的邮件服务器发送邮件,下面是scott water在dottext中写的一个发邮件的类,使用起来比较方便,整个类的代码如下:
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