急求 asp.net 发送邮件的代码,并是能正确发送出邮件的示例,大家帮帮忙啊!很着急的,连带原理也说一下呗!

解决方案 »

  1.   

    http://blog.csdn.net/lff642/archive/2008/07/15/2654346.aspx
    Google实例挺多的 供LZ学习
      

  2.   


    代码很多,原理这个不是一句话就能说清楚的
    代码直接baidu搜索
    原理也一样看后实践即可
      

  3.   

    /// <summary>
            /// 
            /// </summary>
            /// <param name="strSmtpServer">SMTP</param>
            /// <param name="port">SMTP端口号</param>
            /// <param name="strFrom">发信箱地址</param>
            /// <param name="strFromPass">发信箱密码</param>
            /// <param name="strto">收信箱</param>
            /// <param name="strSubject">主题</param>
            /// <param name="strBody">邮件正文</param>
            /// <param name="ssl">是否采用SSL</param>
            public static void SendMail(string strSmtpServer, int port, string strFrom, string strFromPass, string strto, string strSubject, string strBody,bool ssl)
            {
                System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer, port);
                client.EnableSsl = ssl;
                client.UseDefaultCredentials = false;
                client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass);
                client.DeliveryMethod = SmtpDeliveryMethod.Network;            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(strFrom, strto, strSubject, strBody);
                message.BodyEncoding = System.Text.Encoding.UTF8;
                message.IsBodyHtml = true;
                client.Send(message);
            }        /// <summary>
            /// 发送Jmail邮件
            /// </summary>
            /// <param name="strSmtpServer"></param>
            /// <param name="strFrom"></param>
            /// <param name="strFromUser"></param>
            /// <param name="strFromPass"></param>
            /// <param name="strto"></param>
            /// <param name="strSubject"></param>
            /// <param name="strBody"></param>
            public static void SendJmailMail(string strSmtpServer, string strFrom, string strFromUser, string strFromPass, string strto, string strSubject, string strBody)
            {
                jmail.Message jmMessage = new jmail.Message();
                jmMessage.Silent = true;
                jmMessage.Logging = true;
                jmMessage.Charset = "GB2312";
                jmMessage.ContentType = "text/html";
                jmMessage.ISOEncodeHeaders = false;
                jmMessage.From = strFrom;
                jmMessage.FromName = strFrom;
                jmMessage.MailServerUserName = strFromUser;
                jmMessage.MailServerPassWord = strFromPass;
                jmMessage.Subject = strSubject;
                jmMessage.Body = strBody;
                jmMessage.AddRecipient(strto, "", "");
                jmMessage.Send(strSmtpServer, false);          }
      

  4.   

    由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。 202.106.199.35:25 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Net.Sockets.SocketException: 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。 202.106.199.35:25源错误: 
    行 41:         message.BodyEncoding = System.Text.Encoding.UTF8;
    行 42:         message.IsBodyHtml = true;
    行 43:         client.Send(message);
    行 44:     }
    行 45: 
     
    这是什么问题?很着急用啊!
      

  5.   


    你的smtp服务器地址 可用吗,试多几个地址看看
      

  6.   

    protected void submit_Click(object sender, EventArgs e)
        {
            int sendInquiry = 0;
            int minimum = 0;
            int delivery = 0;
            int fob = 0;
            if (cka.Checked == true) { sendInquiry = 1; }
            if (ckb.Checked == true) { minimum = 1; }
            if (ckc.Checked == true) { delivery = 1; }
            if (ckd.Checked == true) { fob = 1; }
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
            String addressee = "[email protected]";
            String body = "";
            string title = subject.Text;
            string sendInquiry1 = "";
            string Minimum1 = "";
            string fob1="";
            string delivery1 = "";
            string Name=ming.Text+xing.Text;
            if (sendInquiry != 1)
            {
                sendInquiry1 = "否";
            }
            else {
                sendInquiry1 = "是";
            }
            if (minimum != 1)
            {
                Minimum1 = "否";
            }
            else
            {
                Minimum1 = "是";
            }
            if (fob != 1)
            {
                fob1 = "否";
            }
            else
            {
                fob1 = "是";
            }
            if (delivery != 1)
            {
                delivery1 = "否";
            }
            else
            {
                delivery1 = "是";
            }        //string content = "Co my e-mail address:" + sendInquiry1 + "\r\n" + "subject:" + subject.Text + "\r\n" + "Minimum order quantity:" + Minimum1 + "\r\n" + "FOB Prices(at min.order quantity):" + fob1 + "\r\n" + "Delivery time:" + delivery1 + "\r\n" + "Expected Order Quantity:" + expected.Text + "\r\n" + "Message:" + message.Text + "\r\n" + "Attachment(s):" + attachment.Text + "\r\n" + "Respone Time:" + ddlDays.Text + "\r\n" + "Sex:" + ddlName.Text + "\r\n" + "Name:" + Name + "\r\n" + "Company Name:" + companyName.Text + "\r\n" + "Business E-mail:" + businessEmail.Text;
            body += "<style>";
            body += "a{ text-decoration:none; color:#444;}";
            body += "body{ font-size:12px; font-family:Arial;}";
            body += "</style>";
            body += "<div style=\"width:807px;  float:left;\">";
            body += "<div style=\"width:806px; height:114px; float:left;\">";
            body += "<div style=\"width:750px; height:30px;\">(*)Required information</div>";
            body += "<div style=\"width:750px; height:25px;\"><div style=\"width:170px; float:left;\">To:</div>&nbsp;Dalian Ponytoy Co.,Ltd</div>";
            body += "<div style=\"width:750px; height:25px;\"><div style=\"width:170px; float:left;\">Co my e-mail address:</div> [" + sendInquiry1 + "] Send me a copy of each inquiry</div>";
            body += "<div style=\"width:750px; height:20px;\"><div style=\"width:170px; float:left;\">Subject</div> [" + subject.Text + "] </div></div>";
            body += "<div style=\"width:806px; height:21px; float:left; background-color:#9bb7b4\"><div style=\"width:200px; float:left; color:#FFFFFF;height:21px; text-align:right\">Inquiry Details</div></div>";
            body += "<div style=\"width:806px; height:299px; float:left; background-image:url(images/inquiry10.gif);\">";
            body += "<div style=\"width:806px; margin-top:20px; height:25px;\">";
            body += "<div style=\"width:170px; float:left; height: 15px;\">Select the inforination&nbsp; you </div><div> [" + Minimum1 + "] Minimum order quantity</div></div>";
            body += "<div style=\"width:806px; height:56px;\">";
            body += "<div style=\"width:170px; height:51px; float:left;\">Want to deceive:</div>";
            body += "<div style=\"height: 23px\"> [" + delivery1 + "] FOB Prices(at min.order quantity)</div>";
            body += " [" + fob1 + "] Delivery time</div>";
            body += "<div style=\"width:806px; height:30px;\">";
            body += "<div style=\"width:170px; float:left;\">Expected Order Quantity: </div>";
            body += "<div> [" + expected.Text + "] </div>";
            body += "</div>";
            body += "<div style=\"width:806px; \"><div style=\"width:170px; float:left;\">Message:</div>[" + message.Text + "]</div>";
            body += "<div style=\"width:806px; height:30px;\"><div style=\"width:170px; float:left;\">Attachment(s):</div> [" + attachment.Text + "] (only for web url)</div>";
            body += "<div style=\"width:806px; height:30px;\"><div style=\"width:170px; float:left;\">Respone&nbsp;Time:</div> Please reply to my inquiry with in [" + ddlDays.Text + "] day(s)</div></div>";
            body += "<div style=\"width:806px; height:21px; float:left\"><div style=\"width:806px; height:21px; float:left; background-color:#9bb7b4\"><div style=\"width:200px; float:left; color:#FFFFFF;height:21px; text-align:right\">Contact Details</div></div></div>";
            body += "<div style=\"width:806px; height:150px; float:left;\">";
            body += "<div style=\"width:806px; height:25px; margin-top:20px;\">";
            body += "<div style=\"width:600px; margin-left:100px;\">";
            body += "<div style=\"width:130px; float:left;\">Sex:[" + ddlName.Text + "]</div>";
            body += "<div style=\"width:130px; float:left;\">Name:[" + Name + "]</div>";
            body += "</div>";
            body += "</div>";
            body += "<div style=\"width:806px; height:25px;\">";
            body += "<div style=\"width:600px; margin-left:100px;\">";
            body += "<div style=\"width:130px; float:left;\">Company Name:</div>[" + companyName.Text + "]";
            body += "</div>";
            body += "</div>";
            body += "<div style=\"width:806px; height:25px;\">";
            body += "<div style=\"width:600px; margin-left:100px;\">";
            body += "<div style=\"width:130px; float:left;\">Business E-mail:</div>[" + businessEmail.Text + "]";
            body += "</div>";
            body += "</div>";
            body += "</div>";
            body += "</div>";
            msg.To.Add(addressee);//收件人 
            msg.From = new MailAddress("[email protected]", "[email protected]", System.Text.Encoding.UTF8);
            /* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/        msg.Subject = title;//邮件标题 
            msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码 
            msg.Body = body;//邮件内容 
            msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码 
            msg.IsBodyHtml = false;//是否是HTML邮件 
            msg.Priority = MailPriority.High;//邮件优先级         SmtpClient client = new SmtpClient();
            client.Credentials = new System.Net.NetworkCredential("[email protected]", "ponytoy.cn");
            //上述写你的GMail邮箱和密码         client.Port = 22;//Gmail使用的端口 
            client.Host = "smtp.gmail.com";
            client.EnableSsl = true;//经过ssl加密 
            object userState = msg;
            try
            {
                client.Send(msg);
                //简单一点儿可以client.Send(msg); 
                //Response.Write("发送成功");
            }
            catch (System.Net.Mail.SmtpException ex)
            {
                Response.Write(ex.Message);
            } 
            //String strINS = "insert into inquiry (sendInquiry,subject,minimum,delivery,fob,expected,message,attachment,response,sex,nameA,nameB,companyName,businessEmail,AddUserID,DisplayLevel,IsActive)";
            //strINS += " values (" + sendInquiry + ",'" + subject.Text + "'," + minimum + "," + delivery + "," + fob + ",'" + expected.Text + "','" + message.Text + "','" + attachment.Text + "','" + ddlDays.Text + "','" + ddlName.Text + "','" + ming.Text + "','" + xing.Text + "','" + companyName.Text + "','" + businessEmail.Text + "','0','0','0')";
            Response.Redirect("index.aspx");
        }
      

  7.   

    呵呵 今天刚做了一个发送邮件的代码 能用 网上也很多这方面的东东 soso就知道了..
      

  8.   

    smtp地址 我写的是smtp.163.com的
    这样可以吗?
    因为我也不知道这个应该怎么写了,还有它还要求端口号,是什么?
      

  9.   

    SendMail.csusing System;
    using System.Data;
    using System.Configuration;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Net.Mail;
    using System.Net;
    /// <summary>
    ///mail 的摘要说明
    /// </summary>
    public class SendMail
    {
        private string sFrom;
        private string spass;
        public SendMail()
        {
            sFrom = "[email protected]"; //邮箱
            spass = "321123";           //密码
        }
        ~SendMail()
        { }    /// <summary>        ///根据传入的内容发送邮件。MessageTo接收者。若多个可用";"隔开.MessageSubject邮件主题。MessageBody邮件内容  /// </summary>
        public bool SendMails(string MessageTo, string MessageSubject, string MessageBody)
        {
            try
            {
                MailAddress from = new MailAddress(sFrom);
                MailAddress to = new MailAddress(MessageTo);
                MailMessage message = new MailMessage(from, to);
                message.Subject = MessageSubject;       //发送邮件的标题 
                message.Body = MessageBody;              //发送邮件的内容 
                message.Priority = MailPriority.High;  //发送邮件的优先等级
                message.IsBodyHtml = true;
                //if (FileUpload1.PostedFile.FileName != "") 
                //{//发送附件 
                //    Attachment att = new Attachment(FileUpload1.PostedFile.FileName); 
                //    message.Attachments.Add(att); 
                //}             string strSC = "smtp." + sFrom.Substring(sFrom.IndexOf("@") + 1);            SmtpClient client = new SmtpClient(strSC);
                client.UseDefaultCredentials = false;
                client.Credentials = new NetworkCredential(sFrom, spass);
                client.DeliveryMethod = SmtpDeliveryMethod.Network;            client.Send(message);
                return true;
            }
            catch (InvalidOperationException io)
            {
                string str = io.Message;
                return false;
            }
            catch (SmtpException se)
            {
                string str = se.Message;
                return false;
            }
        }
    }调用方法
    Send(txtEmail.Text.Trim(), title.Text.Trim(), content.Text.Trim());
      

  10.   

    smtp.163.com 记得以前不支持 非本地发邮件的吧...
    smtp 端口一般是 25 pop3 好像是110
      

  11.   

    调用错误了!我的类是直接放在App_Code下的
    正确调用SendMail st = new SendMail();
    st.SendMails(txtEmail.Text.Trim(), title.Text.Trim(), content.Text.Trim());
      

  12.   

    Jmail发送,一个不错的方法:
    需要引用jmail.dll组件,网上可以下载//发送邮件
        public void sendEmail(string sender, string senderuser, string euser, string epwd, string receiver, string subject, string body, string eserver)
        {
            jmail.MessageClass jmMessage = new jmail.MessageClass();
            jmMessage.Charset = "GB2312";
            jmMessage.ISOEncodeHeaders = false;
            jmMessage.From = sender;
            //jmMessage.ContentType = "text/html";
            jmMessage.FromName = senderuser;
            jmMessage.Subject = subject;
            jmMessage.MailServerUserName = euser;
            jmMessage.MailServerPassWord = epwd;
            jmMessage.AddRecipient(receiver, "", "");
            if (this.upFile.PostedFile.ContentLength != 0)
            {
                string sFilePath = this.upFile.PostedFile.FileName;
                jmMessage.AddAttachment(@sFilePath, true, "");            string sfilepash2 = this.upFile2.PostedFile.FileName;
                jmMessage.AddAttachment(@sfilepash2, true, "");
             }
            jmMessage.Body = body;
            if (jmMessage.Send(eserver, false))
            {
                 Response.Write("<script language=javascript>alert('发送成功')</script>");
            }
            else
            {
                Response.Write("<script language=javascript>alert('发送失败,请仔细检查邮件服务器的设置是否正确!')</script>");
                jmMessage = null;
                return;
            }
        }
      

  13.   


      protected void Button1_Click(object sender, EventArgs e)
        {
            DataSet ds = bll.Getmaxstaffcodeid();
            string id = ds.Tables[0].Rows[0][0].ToString();        string newid;
            if (id == "" && id == null)
            {
                newid = "00000";
            }
            else
            {
                newid = Convert.ToString(Convert.ToInt32(id) + 1).PadLeft(5, '0');
            }
            staff.Staffcode = type + year + newid;//生成流水号
            if (this.yzm.Text.ToString().ToUpper() == this.IMGCODE1.Text)
            {
                if (eastelite.DIP.BLL.staffBll.addregister(staff))
                {
                    Session["reg"] = staff;//存入session
                    MailMessage mail = new MailMessage();
                    staffModel s = Session["reg"] as staffModel;//接收session
                    string mailfrom = System.Configuration.ConfigurationManager.AppSettings["servermailname"].ToString();
                    string mailto = this.mail.Text.ToString().Trim();
                    string mailpwd = System.Configuration.ConfigurationManager.AppSettings["servermailpwd"].ToString();
                    mail.BodyFormat = System.Web.Mail.MailFormat.Html;
                    mail.To = this.mail.Text;  //接受人的邮箱
                    mail.From = mailfrom;  //你自己的邮箱(注意qq邮箱不行)
                    mail.Subject = this.people.Text.ToString() + ",您好,感谢您注册******(北京)科技有限公司系统帐户";  //邮箱标题
                    mail.Body = "尊敬的" + this.people.Text + ":<br>感谢您对于本系统的支持与关注!<br>您的注册信息如下:<br>系统帐号:<font color='red'>" + s.Staffcode + "</font><br>系统密码:<font color='red'>"
                        + this.pwd.Text + "</font><br>用户名:<font color='red'>" + this.people.Text + "</font><br>安全邮箱:<font color='red'>" + this.mail.Text;
                    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
                    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //stmp验证
                    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", mailfrom);
                    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", mailpwd);
                    SmtpMail.SmtpServer = "smtp.ym.163.com";  //企业代理邮件服务器
                    SmtpMail.Send(mail);
                    cleartext();//清空文本
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "str", "<script>window.open('regdetatile.aspx',target='_self');</script>");//弹出信息显示页面
                }
                else
                {
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "str", "<script>alert('抱歉。注册提交失败。请刷新后重新尝试!')</script>");
                }
            }
            else
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "str", "<script>alert('验证码错误。请重新填写!')</script>");
            }
        }
    帐号密码写在配置文件  Ok了
      

  14.   

    //可以群发,用","分隔
                        string toMails = txtMessage.Text;
                        //主题
                        string subject = txtsend.Text;
                        //正文
                        string body = txtContent2.Text
                        string smtpServer = ConfigurationManager.AppSettins 
    ["SmtpServer"].ToString();
                        //发件人账号 要修改,到时候用必乐的共用邮箱
                        string from = ConfigurationManager.AppSettings["UserName"].ToString();
                        //发件人密码
                        string credential = ConfigurationManager.AppSettings["Pwd"].ToString();                    SmtpClient client = new SmtpClient(smtpServer);
                        client.Credentials = new NetworkCredential(from, credential);                    MailMessage mailMsg = new MailMessage();
                        mailMsg.From = new MailAddress(from);
                        mailMsg.Subject = subject;
                        mailMsg.Body = body;
                        mailMsg.IsBodyHtml = true;                    string[] arrEmail = toMails.Split(',');
                                               for (int i = 0; i < arrEmail.Length; i++)
                            {
                                mailMsg.To.Add(arrEmail[i]);
                            }
                            client.Send(mailMsg);
                            this.ClientScript.RegisterStartupScript(typeof(Page), "javaScript", "alert('邮件发送成功')", true);
                                                
      

  15.   

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>找回密码</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
                <table border="0" cellspacing="0" cellpadding="0" style="width: 442px; height: 12px;" id="TABLE1" onclick="return TABLE1_onclick()">
                  <tr>
                    <td align="left" valign="middle" style="width: 137px; height: 16px;">用户名:</td>
                    <td colspan="2" align="left" valign="middle" style="width: 213px; height: 16px;">
                        <asp:TextBox ID="txtName" runat="server" CssClass="loginwbk" ValidationGroup="11"></asp:TextBox><asp:RequiredFieldValidator
                            ID="RequiredFieldValidator1" runat="server" ErrorMessage="请您输入用户名!" ControlToValidate="txtName" ValidationGroup="11">*</asp:RequiredFieldValidator></td>
                  </tr>
                    <tr>
                        <td align="left" valign="middle" style="width: 137px; height: 16px;">密码提示问题:</td>
                         <td colspan="2" align="left" valign="middle" style="width: 213px; height: 16px;">
                           <label><asp:TextBox ID="txtanswer" runat="server"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtanswer"
                    ErrorMessage="请输入密码提示问题" Font-Size="10pt">*</asp:RequiredFieldValidator></label>
                        </td>
                    </tr>
                      <tr>
                       <td align="left" valign="middle" style="width: 137px; height: 16px;">密码提示答案:</td>
                       <td colspan="2" align="left" valign="middle" style="width: 213px; height: 16px;">
                       <label><asp:TextBox ID="txtresult" runat="server"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtresult"
                    ErrorMessage=" 请输入密码提示答案" Font-Size="10pt">*</asp:RequiredFieldValidator></label>
                        </td>
                      </tr>
                      <tr>
                      <td align="left" valign="middle" style="width: 137px; height: 16px;">邮箱账号:</td>
    <td style="height: 30px">
                <span class="red_star">
                    <asp:TextBox ID="txtSendEmail" runat="server" Width="150px"></asp:TextBox></span></td>
        </tr>
                      <tr>
                      <td align="left" valign="middle" style="width: 137px; height: 16px;">发送者邮箱服务器:</td>
     <td>
                <span class="red_star">&nbsp;<asp:DropDownList ID="DropDownList2" runat="server" Width="133px"  DataTextField="name" DataValueField="name">                    
                    <asp:ListItem Value="smtp.ym.163.com">网易163企业邮箱</asp:ListItem>
                    <asp:ListItem Value="smtp.126.com">网易126邮箱</asp:ListItem>
                    <asp:ListItem Value="smtp.163.com">网易163邮箱</asp:ListItem>
                    <asp:ListItem Value="smtp.qq.com">qq邮箱</asp:ListItem>
                    <asp:ListItem Value="smtp.sina.com">新浪邮箱</asp:ListItem>
                    <asp:ListItem Value="smtp.mail.yahoo.com">雅虎邮箱</asp:ListItem>
                    <asp:ListItem Value="smtp.sohu.com">搜狐邮箱</asp:ListItem>
                    <asp:ListItem Value="smtp.gmail.com">谷歌邮箱Gmail</asp:ListItem>
                    </asp:DropDownList>注(选择相应的邮件发送服务器,否则可能出现发送不成功!)</span></td>
    </tr>
                  <tr>
                  
                    <td align="left" valign="middle" style="width: 137px; height: 25px;">&nbsp;</td>
                    <td colspan="2" align="left" valign="middle" style="width: 213px; height: 25px">
                        <asp:Button ID="Button1" runat="server" Text="确定" OnClick="Button1_Click" />
                    </td>
                  </tr>
                </table>
                </div>
          </form>
    </body>
    </html>
    后台实现代码:    protected void Page_Load(object sender, EventArgs e)
        {}
    //按钮事件
        protected void Button1_Click(object sender, EventArgs e)
        {
            string sql = "select * from userinfo where  username='" + txtName.Text.Trim() + "'";
            DataTable dt = Common.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                string pwd = Convert.ToString(dt.Rows[0][3]);//密码
                string answer=Convert.ToString(dt.Rows[0][2]);//问题
                string result=Convert.ToString(dt.Rows[0][4]);//答案
                string email = Convert.ToString(dt.Rows[0][5]);//邮箱地址
                string content = "尊敬的:" + email + "您好!您填写的验证信息通过,我们已经帮您找回了密码,您的密码是: " + pwd;
                if (answer.ToString().Equals(answer) && result.ToString().Equals(result)) {
                  
                    //调用发送方法
                    SendSMTPEMail(DropDownList2.SelectedValue, txtSendEmail.Text.Trim(),content);       
                }
                Response.Write("<script>alert('邮件已经发送成功!请到您的邮箱去确认密码!');location.href='" + Request.Url.ToString() + "';</script>");
            }
            else
            {
                Response.Write("<script>alert('用户名或提示问题,答案错误!');location.href='" + Request.Url.ToString() + "';</script>");
            }
    }//发送邮件方法(发送者的服务器类型,接收者邮箱地址,发送的内容
        public void SendSMTPEMail(string strSmtpServer, string strto, string strBody)
        {
            System.Net.Mail.SmtpClient client = new SmtpClient("smtp.sina.com");//发送者的服务器类型
              client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential("haiyan1989118", "renhaiyan1989118");//发送者的用户名,密码
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            System.Net.Mail.MailMessage message = new MailMessage("[email protected]", strto, "[密码找回]", strBody);//发送者邮箱,接收者邮箱,发送的标题,发送的内容
            message.BodyEncoding = System.Text.Encoding.UTF8;
            message.IsBodyHtml = true;
            client.Send(message); 
    }附加:    <asp:ListItem Value="smtp.ym.163.com">网易163企业邮箱</asp:ListItem>
        <asp:ListItem Value="smtp.126.com">网易126邮箱</asp:ListItem>
        <asp:ListItem Value="smtp.163.com">网易163邮箱</asp:ListItem>
        <asp:ListItem Value="smtp.qq.com">qq邮箱</asp:ListItem>
        <asp:ListItem Value="smtp.sina.com">新浪邮箱</asp:ListItem>
        <asp:ListItem Value="smtp.sohu.com">搜狐邮箱</asp:ListItem>
    <asp:ListItem Value="smtp.gmail.com">谷歌邮箱Gmail</asp:ListItem>
       <asp:ListItem Value="smtp.mail.yahoo.com">雅虎邮箱</asp:ListItem>