发送邮箱密码找回 比如qq邮箱

来源:互联网 发布:手机改淘宝店铺名字 编辑:程序博客网 时间:2024/04/28 21:56

1.在qq邮箱中设置, 开启pop3协议,自动生成密码   记住密码(下边用)

2. 前台页面

 <tbody>
                      <tr>
                <td width="138" align="right"><span class="f_f15a22">*</span>用户名:</label></td>
                <td width="260"><input runat="server" id="username" name="username" type="text" class="input w205 inputFocus"></td>
                <td><div class="tips" id="loginPwd_tips"></div></td>
              </tr>

            
                  <tr>
                    <td width="138" align="right"><span class="f_f15a22">*</span>邮箱:</td>
                    <td width="260"><input  runat="server" id="email" name="email" type="text" class="w250 input inputFocus grays" placeholder="请输入有效的邮箱"></td>
  </tbody> 


后台代码

    命名空间 
                   using System.Net;
                        using System.Net.Mail;

protected void Button1_Click(object sender, EventArgs e)
{
string name = username.Value;//输入的用户名
string useremail = email.Value;//输入的邮箱
string selsql = "select * from 表 where realname='" + name + "' and email='" + useremail + "'";
DataTable tab = ClassFile.SqlHelper.GetTable(selsql);
if (tab.Rows.Count > 0)
{
string sqlpwd = tab.Rows[0]["password"].ToString();
MailMessage mailmessage = new MailMessage();//创建一个邮件对象
mailmessage.From = new MailAddress("开启pop3服务的邮箱比如:**@qq.com", "用户名 比如:qq昵称");//设置发件人账户 用户名
mailmessage.To.Add(new MailAddress(useremail));//设置收件人账号
mailmessage.Subject = "hello 秘密邮件 请勿泄露";//设置主题
mailmessage.Body = "呀呀呀 请记住呀----"+sqlpwd;//设置正文内容 密码
//制定smtp 服务器地址
SmtpClient smtpclient = new SmtpClient("smtp.qq.com");//smtp.163.com
smtpclient.Credentials = new NetworkCredential("开启pop3服务的邮箱比如:**@qq.com", "邮箱设置开启pop3服务时的密码");//设置账户密码 密码是邮箱中设置开启pop3自动生成的密码
smtpclient.EnableSsl = true;//指定 SmtpClient 使用安全套接字层 (SSL) 加密连接。
smtpclient.Send(mailmessage);//发送邮件
}
}

0 0
原创粉丝点击