当前位置:编程学习 > C#/ASP.NET >>

.net网站用户注册后,网站不给用户发激活邮件是怎么回事。代码如下

网站后台:有个设置邮箱和密码的项目不知道和代码有没有关系。谢谢各位

using System;
using System.Collections;
using System.Configuration;
using System.Data;
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;
public partial class Hyregister : System.Web.UI.Page
{
    DBHelper db = new DBHelper();
    protected void Page_Load(object sender, EventArgs e)
    {
        form1.DefaultButton = "zcbt";
    }
    protected void checkname_Click(object sender, EventArgs e)
    {
        if (Txtname.Text.Trim() == "")
        {
            Response.Write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
            Response.Write("<script language=javascript>alert('请输入用户名!');</script>");
            Txtname.Focus();
        }
        else
        {
            string checksql = "select count(*) from userinfo where username='" + Txtname.Text.Trim() + "'";
            int j = db.getExeScar(checksql);
            if (j > 0)
            {
                Response.Write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
                Response.Write("<script language=javascript>alert('该用户名已经存在!');</script>");

                Txtname.Focus();
            }
            else
            {
                Response.Write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
                Response.Write("<script language=javascript>alert('恭喜你,此用户名可以使用!');</script>");
            }
        }
    }
    protected void zcbt_Click(object sender, EventArgs e)
    {
        string sql;
        string checkcode=Txtyzm.Text.Trim();
        if (Session["CheckCode"] != null)
        {
            if (string.Compare(Session["CheckCode"].ToString(), checkcode, true) == 0)
            {
                string uname = Txtname.Text.Trim().Replace("'", "");
                string pwd = Txtpwd.Text.Trim().Replace("'", "");
                pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "md5");
                string sex = Dropsex.SelectedItem.Text;
                string age = Txtage.Text;
                string phone = Txtphone.Text.Trim();
                string email = Txtemail.Text.Trim().Replace("'", "");
                string address = Txtaddress.Text.Replace("'", "");

                string checkname = "select count(*) from userinfo where username='" + uname + "' ";
                int k = db.getExeScar(checkname);
                if (k > 0)
                {
                    Response.Write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
                    Response.Write("<script language=javascript>alert('该用户名已经存在!');</script>");
                    Txtname.Focus();
                }
                else
                {

                    int j = db.getExeScar("select count(*) from userinfo where username='" + Txtemail.Text + "'");
                    if (j > 0)
                    {
                   
                        string tjsql = "insert into tb_tjname (tjname,btjname) values('" + email + "','" + uname + "')";
                        db.getExeSQL(tjsql);
                        string getjf = "update userinfo set hasjf=hasjf+30 where username='" + email + "'";
                        db.getExeSQL(getjf);
                    }
                    else
                    {
                        Response.Write("<script language=javascript>alert('推荐人不存在!');</script>");
        
                    }
                    try
                    {
                        string[] emailserver = Txtname.Text.Split('@');
                        string jh = Server.UrlEncode(pwd);
                        string mysql = "select * from myemail where myemailid=1";
                        DataSet dszc = db.getDS(mysql);
                        string myemail = dszc.Tables[0].Rows[0]["myemail"].ToString();
                        string mypwd = dszc.Tables[0].Rows[0]["mypwd"].ToString();
                        string emailtitle = "你好,这个是一个激活的链接";
                        string emailcontent = "您刚刚在石家庄外卖网上注册了一个帐号,<br/>这是石家庄石家庄外卖网的一个激活链接,<a href=http://www.sjzwm.cn/userjh.aspx?jihuo=" + jh + "&username=" + uname + " target=_blank>点击激活帐号</a>";
                        SendSMTPEMail("smtp." + emailserver[1], myemail, mypwd, Txtname.Text, emailtitle, emailcontent);
                    }
                    catch { }    
                    sql = "insert into userinfo (username,pwd,sex,age,phone,address,hasjf,jihuo) ";
                        sql += " values ('" + uname + "','" + pwd + "','" + sex + "','" + age + "','" + phone + "','" + address + "',20,0)";
                    int i = db.getExeSQL(sql);
                    if (i > 0)
                    {
                        Response.Write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
                        Response.Write("<script language=javascript>alert('注册成功!请查看您的邮箱,点击激活帐号');window.location='Hylogin.aspx';</script>");
                        // Response.Redirect("Hylogin.aspx");
                    }
                    else
                    {
                        Response.Write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
                        Response.Write("<script language=javascript>alert('注册失败!');</script>");
                    }
                }

            }
            else
            {
                Response.Write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
                Response.Write("<script language=javascript>alert('验证码错误!');</script>");
            }
        }
        else
        {
            Response.Write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
            Response.Write("<script language=javascript>alert('请刷新验证码!');</script>");
        }
    }

    /*
     第一个参数如果是163邮箱就写smtp.163.com
第二个参数发件人的帐号
第三个参数发件人密码
第四个参数收件人帐号
第五个参数主题
第六个参数内容.

     */
    public void SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody)
    {
        System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer);
        client.UseDefaultCredentials = false;
        client.Credentials =
        new System.Net.NetworkCredential(strFrom, strFromPass);
        client.DeliveryMethod = SmtpDeliveryMethod.Network;

        System.Net.Mail.MailMessage message =
        new MailMessage(strFrom, strto, strSubject, strBody);
        message.BodyEncoding = System.Text.Encoding.UTF8;
        message.IsBodyHtml = true;
        client.Send(message);
    }

}

--------------------编程问答-------------------- 我先自己顶起!!!!!! --------------------编程问答-------------------- 我再顶起。。。。。。。。。。。。。。。。高手来吧 。拜托
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,