发Email出现错误!!!(在线等)
注册
检验没问题后
录入数据库;
try{
SM.AdminEmail="000@000.net.cn";
SM.UserName="000@000.net.cn";
SM.Password="000000"; SM.SmtpServer="22.16.120.103";
SM.EMailFormat="Html";
string mailContent=RealName.Text+"你好\r\n你的帐号 :"+UserName.Text+"\r\n你的密码:"+tem.ToString()+"\r\n \r\n\r\n恭喜你成为超 SM.Send(Email.Text.ToString().Trim().Replace(" ",""),"lsb@lsb.net.cn","注册超脑力会员成功!",mailContent);
Response.Write("<script language=\"javascript\">alert('注册用户成功!登陆密码已经发送到您的信箱中,请从首页登陆!');window.location.href='../index.aspx';</script>");
Response.End();
}
catch
结果很多时候EMAIL收不到信
------------------------------
public class SystemMail
{
private string _adminEmail;
private string _smtpServer = "localhost";
private string _password;
private string _userName;
private string _mailFormat;
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 string EMailFormat
{
get{return _mailFormat;}
set{_mailFormat = 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;
if (this.EMailFormat=="Html")
{
em.BodyFormat=MailFormat.Html;
}
//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;
}
}