C# 通过发送邮箱找回密码

网上找了很多,但实际应用的时候会报错,呵呵,现在我结合了老师的例子,加上自己的亲身体验总结了一下这个方法,其实也很简单的,之前也有前辈们写过了,不过想想还是自己再写一边吧,哈哈,不多说了,跟我一起做吧:

<span style="font-size:16px;">    /// <summary>  
    /// 发送密码前的判断  
    /// </summary>  
    /// <param name="sender"></param>  
    /// <param name="e"></param>  
    /// *** 12.1am  
    protected void BtnFind_Click(object sender, EventArgs e)  
    {  
            string LoginName = "yhl";  
            EC_Puser ep = EC_PuserManager.GetEC_PuserByPUserID(LoginName);  
            if (ep != null && ep.Email == email.Text.Trim())  
            {  
                sendEmail(email.Text.Trim(), "找回密码", "尊敬的用户:通过Eshop网购管理中心审请找回密码<br/>您的密码是                 :" + ep.Pwd.ToString() + "", "Sara_yhl@sina.com", "123456");  
                Response.Write("<script>alert('密码已发送到您的邮箱,请注意查收!');</script>");  
            }  
    }</span>

以下这个方法只要调用即可:

 /// <summary>  
    /// 发送邮件  
    /// </summary>  
    /// <param name="tomail">收件人邮件地址</param>  
    /// <param name="title">标题</param>  
    /// <param name="content">邮件正文</param>  
    /// <param name="FormUser">发件人账号</param>  
    /// <param name="userPwd">发件人密码</param>  
    public static void sendEmail(string tomail, string title, string content, string FormUser, string userPwd)  
    {  
        MailAddress from = new MailAddress(FormUser);  
        MailAddress to = new MailAddress(tomail);  
        MailMessage MyMessage = new MailMessage(from, to);  
        MyMessage.Priority = MailPriority.Normal;  
        MyMessage.Priority = MailPriority.Normal;  
  
        MyMessage.IsBodyHtml = false;  
        MyMessage.IsBodyHtml = true;  
        MyMessage.Body = content;  
        MyMessage.BodyEncoding = System.Text.Encoding.UTF8;  
        MyMessage.Subject = title;  
  
  string SmtpServer = "smtp.sina.com";//这里使用你服务器端发送的邮箱smtp协议  # #新浪邮箱的:<strong></strong><pre name="code" class="csharp" style="display: inline !important; "><pre name="code" class="csharp" style="display: inline !important; ">smtp.sina.com网易邮箱:"smtp.126.com";  QQ邮箱:smtp.qq.com</pre><pre name="code" class="csharp" style="display: inline !important; ">        SmtpClient client = new SmtpClient(SmtpServer);  
        System.Net.NetworkCredential cred = new System.Net.NetworkCredential(FormUser, userPwd);  
        client.Credentials = cred;  
        client.Send(MyMessage);<pre></pre><br>  
<p></p>  
<pre></pre>  
<pre></pre>  
<pre></pre>  
</pre></pre>

转自qq_32915337的博客:http://blog.csdn.net/qq_32915337/article/details/62428531

 

发表评论

相关文章

没有相关文章!

猜你喜欢