注册成功后自动发送邮件到他的邮件功能该如何实现?

解决方案 »

  1.   


        protected void btnSeek_Click(object sender, EventArgs e)
        {
            connection conn = new connection();
            SqlConnection con = conn.con1();
            if (txtAnswer.Text.Trim() == Session["answer"].ToString())
            {
                string emailstr = "select email from dbusers where uid='" + txtName.Text.Trim() + "'";
                con.Open();
                SqlCommand cmd = new SqlCommand(emailstr, con);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    string userEmail = dr[0].ToString();
                    System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage("[email protected]",userEmail);
                    myMail.Subject = "" + txtName.Text + ",您好:";
                    myMail.Body = "您在XYZ商城的登录密码是" + Session["pwd"].ToString() ;
                    System.Net.Mail.SmtpClient clt = new System.Net.Mail.SmtpClient("smtp.163.com", 25);
                    clt.Credentials = new System.Net.NetworkCredential("[email protected]", "******");
                    clt.Send(myMail);
                    con.Close();
                    Response.Write("<script language=jscript>alert('密码已经发到您的邮箱里了,请注意查收。')</script>");
                }        }
            else
            {
                Response.Write("<script language>alert('Error answer!')</script>");
            }
        }
    这是找回密码的代码,原理是一样的,供参考
      

  2.   

    就是在注册成功后执行个发送邮件功能就可以了
    推荐使用dotnetopenmail发送 如何发送可以参考我的csdn博客
      

  3.   

    userEmail 
    你还要有开通smtp pop3功能得邮箱哦
    04年以前的163可以 用
      

  4.   

     protected void btnSeek_Click(object sender, EventArgs e)
        {
            connection conn = new connection(); //连接数据库
            SqlConnection con = conn.con1();
            if (txtAnswer.Text.Trim() == Session["answer"].ToString())
            {
                string emailstr = "select email from dbusers where uid='" + txtName.Text.Trim() + "'";
                con.Open();
                SqlCommand cmd = new SqlCommand(emailstr, con);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read()) //存在用户名对用的email 就执行发邮件
                {
                    string userEmail = dr[0].ToString();
                    System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage("[email protected]",userEmail); //引用Net命名控件,
                    myMail.Subject = "" + txtName.Text + ",您好:";//title
                    myMail.Body = "您在XYZ商城的登录密码是" + Session["pwd"].ToString() ;//Content
                    System.Net.Mail.SmtpClient clt = new System.Net.Mail.SmtpClient("smtp.163.com", 25);邮箱服务器
                    clt.Credentials = new System.Net.NetworkCredential("[email protected]", "******");//邮箱得用户名和密码
                    clt.Send(myMail);
                    con.Close();
                    Response.Write("<script language=jscript>alert('密码已经发到您的邮箱里了,请注意查收。')</script>");
                }        }
            else
            {
                Response.Write("<script language>alert('Error answer!')</script>");
            }
        }