请问实现密码注册后,将密码自动发送到用户的邮箱里,如何做呢?
具体用到什么类???代码是
最好是c#

解决方案 »

  1.   

    public void SendMail(string toUser, string password, string name)
        {
            MailMessage mail = new MailMessage();//实像化MAIL对像
            mail.To = "[email protected]";//接收者
            mail.From = "[email protected]";//发送者
            mail.Subject = "找回密码";//主题
            mail.Body = "您好:" + name + "  您的密码是:" + password + " 请您记好您的密码!";//内容
            mail.BodyEncoding = Encoding.GetEncoding("GB2312");//编码        
            //smtp服务器     
            //SmtpMail.SmtpServer = "smtp.sina.com";
            SmtpMail.SmtpServer = "127.0.0.1";
            // SmtpMail.SmtpServer.Insert( 0,"127.0.0.1 or pop.163.com");
            mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = "1";
            //帐号
            mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "52aspx";
            //密码
            mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "******";
            try
            {
                SmtpMail.Send(mail);
                this.lblSuccess.Text = "发送成功,请检查您的邮箱!";
            }
            catch (Exception ex)
            {
                this.lblSuccess.Text = ex.Message;
            }
        }
      

  2.   

    http://aspxboy.com/private/227/default.aspx
    http://dev.csdn.net/article/21/21402.shtm
      

  3.   


    在vs2005中发送邮件的方法如下:
                System.Net.Mail.SmtpClient client = new SmtpClient();
                client.Host = "smtp.163.com";
                client.UseDefaultCredentials = false;
                client.Credentials = new System.Net.NetworkCredential("你的163用户名", "*****");
                //星号改成自己邮箱的密码
                client.DeliveryMethod = SmtpDeliveryMethod.Network;            System.Net.Mail.MailMessage message = new MailMessage("你的163邮箱地址", "收件人邮箱地址");
                message.Subject = "测试";
                message.Body = "用自己写的软件发的邮件!";
                message.BodyEncoding = System.Text.Encoding.UTF8;
                message.IsBodyHtml = true;
               //添加附件
                Attachment data = new Attachment(@"附件地址如:e:\a.jpg", System.Net.Mime.MediaTypeNames.Application.Octet);
                message.Attachments.Add(data);            try
                {
                    client.Send(message);
                    MessageBox.Show("Email successfully send.");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Send Email Failed." + ex.ToString());
                }
    参考文章:
    http://www.cnblogs.com/jailu/archive/2007/04/10/707036.htmlhttp://www.cnblogs.com/yyw84/archive/2006/05/17/402381.html
      

  4.   

    gaoliuchang:
    你的代码可以实现邮件的发送,可是,附件不行错误提示:
    不支持给定路径的格式。
      

  5.   

    如果是 asp.net 2.0 
    1 楼是可以的.
    3 楼是推荐的
      

  6.   

    注册时发送到邮箱去
    public void sendEmail(string email, string name)
        {
            try
            {
                jmail.Message jmessage = new jmail.Message();
                jmessage.Charset = "GB2312";
                jmessage.From = new functions().getInfoXX("t_Parameters", "p_name", "网站电子邮箱", "p_value").Trim();
                // 发信地址  
                jmessage.MailServerUserName = new functions().getInfoXX("t_Parameters", "p_name", "网站电子邮箱", "p_value").Trim();
                //smtp认证用户名(注:如为网易用户,不加要@163.com,只要前面部分即可)
                jmessage.MailServerPassWord = new functions().getInfoXX("t_Parameters", "p_name", "网站电子邮箱密码", "p_value").Trim();
                // smtp论证用户名密码             jmessage.FromName = "108人力银行";
                // 发信人    
                jmessage.ReplyTo = new functions().getInfoXX("t_Parameters", "p_name", "网站电子邮箱", "p_value");
                // 回复地址    
                jmessage.ContentType = "text/html";//邮件内容为html
                jmessage.Subject = "您已成功注册108人力银行个人会员";            //string strbody = "<br>" + name + "您好!<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;欢迎您注册108人力银行个人会员。<br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;108人力银行个人会员<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+DateTime.Now.Date;//邮件内容
                string strbody = "";
                strbody += new functions().getInfoXX("t_pagetexts", "p_name", "个人注册邮件反馈","p_value").Replace("$",name);
                jmessage.HTMLBody = strbody;
                // 邮件标题 
                jmessage.AddRecipient(email, "", "");
                jmessage.Send("mail.108ren.com", false);//发送邮件smtp.163.com
                jmessage.Close();//关闭对象,释放资源
            }
            catch (Exception err)
            {
                Response.Write(err);
            }
    使用方法是 this.sendEmail(email.Text.Trim(),username.Text.Trim());邮箱和用户名文本框 new functions().getInfoXX的方法是
            /// table:表 /// bm:where条件中的数据表字段名称/// bmvalue:where 条件中的数据表字段内容
    /// tname:需要查询的表字段名称
            public string getInfoXX(string table, string bm, string bmvalue, string tname)
            {
                DBconn DB = new DBconn();
                string bh = DB.getExecuteString("select " + tname + " from " + table + " where " + bm + "='" + bmvalue + "'");
                return bh;
            }下面的是找回密码时发送到用户邮箱代码使用方法和上面的一样 public void sendEmail(string email, string name)
        {
            try
            {
                jmail.Message jmessage = new jmail.Message();
                jmessage.Charset = "GB2312";
                jmessage.From = "[email protected]";
                // 发信地址  
                jmessage.MailServerUserName = "86085005";
                //smtp认证用户名(注:如为网易用户,不加要@163.com,只要前面部分即可)
                jmessage.MailServerPassWord = "kingseer";
                // smtp论证用户名密码             jmessage.FromName = "108人力银行";
                // 发信人    
                jmessage.ReplyTo = "[email protected]";
                // 回复地址    
                jmessage.ContentType = "text/html";//邮件内容为html
                jmessage.Subject = "108人力银行临时密码";             string strbody = "";
                 strbody += new functions().getInfoXX("t_pagetexts", "p_name", "找回密码邮件反馈-个人", "p_value").Replace("$", name).Replace("@%", lspass);
                jmessage.HTMLBody = strbody;
                // 邮件标题 
                jmessage.AddRecipient(email, "", "");
                jmessage.Send("smtp.163.com", false);//发送邮件smtp.163.com
                jmessage.Close();//关闭对象,释放资源
            }
            catch (Exception err)
            {
                Response.Write(err);
            }
        }
      

  7.   

    日来晚了NND还得我白弄了5555555