zoukankan      html  css  js  c++  java
  • 牛腩购物 19:用户密码找回功能 smtp 发信 qq邮箱

    smtp 发信类:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net.Mail;
    using System.Net;

    namespace Niunan.Shop.Utility
    {
        /// <summary>邮件发送类
       
    ///
        /// </summary>
       
    public class email
       
    {
             //using System.Net.Mail;
             // using System.Net;

           
    /// <summary>发送email,默认是25端口.用法:SendMail("邮件标题", "你的密码是:" , 收件人地址, "发信人完整邮箱地址", "发信人完整邮箱地址", "密码", "smtp.qq.com(QQ的smtp地址,不同的域名邮箱地址不通)")
           
    ///
            /// </summary>
            /// <param name="title">
    邮件标题</param>
            /// <param name="body">
    邮件内容</param>
            /// <param name="toAdress">
    收件人</param>
            /// <param name="fromAdress">
    发件人</param>
            /// <param name="userName">
    发件用户名</param>
            /// <param name="userPwd">
    发件密码</param>
            /// <param name="smtpHost">
    smtp地址</param>
           
    public static void SendMail(string title, string body, string toAdress, string fromAdress,
                                  string userName, string userPwd, string smtpHost)
            {
                try
               
    {
                    MailAddress to = new MailAddress(toAdress);
                    MailAddress from = new MailAddress(fromAdress);
                    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);
                    message.IsBodyHtml = true; // 如果不加上这句那发送的邮件内容中有HTML会原样输出
                   
    message.Subject = title; message.Body = body;
                    SmtpClient smtp = new SmtpClient();
                    smtp.UseDefaultCredentials = true;
                    smtp.Port = 25;
                    smtp.Credentials = new NetworkCredential(userName, userPwd);
                    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                    smtp.Host = smtpHost;
                    //message.To.Add(toAdress);  //用 To.Add方法能增加收件箱的号码
                   
    smtp.Send(message);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

        }
    }

    使用方法:  点击获取密码之后

    image

    protected void btnGet_Click(object sender, EventArgs e)
           {
               string username = Request.QueryString["username"];
               string answer = txtAnswer.Text.Trim();
               if (answer.Length == 0)
               {
                   Niunan.Shop.Utility.Tool.alert("请填写答案", this.Page);
                   return;
               }
               if (string.IsNullOrEmpty(username))
               {
                   Niunan.Shop.Utility.Tool.alert("用户名不能为空", "getpwd1.aspx", this.Page);
                   return;
               }
    
               Niunan.Shop.Model.User u = new DAL.UserDAO().GetModel(username);
               if (u != null)
               {
                   if (answer == u.answer)  //如果答案相同,开始发信
                   {
                       Niunan.Shop.Utility.email.SendMail("您在 牛腩购物网的密码已经取回", "您的密码是:" + u.password, u.email, 
    "1727050508@qq.com", "1727050508@qq.com", "这里输入邮箱的密码", "smtp.qq.com");
                       Niunan.Shop.Utility.Tool.alert("您的密码已经发送到您的邮箱"+u.email+"中", "default.aspx", this.Page);
                   }
                   else
                   {
                       Niunan.Shop.Utility.Tool.alert("答案错误",   this.Page);
                       return;
                   }
               }
               else
               {
                   Niunan.Shop.Utility.Tool.alert("用户名不存在", "getpwd1.aspx", this.Page);
                   return;
               }
           }
    
  • 相关阅读:
    新零售的舞台上,创业者如何与大象共舞
    无人零售的黑科技:RFID技术
    中台服务架构的一点思考
    大中台+小前台概念
    如何根据对象的属性,对集合(list / set)中的对象进行排序
    fzu 1075 分解素因子
    POJ 1442 Black Box(优先队列)
    Linux正則表達式-定位元字符
    排序算法之希尔排序
    人工神经网络简单介绍
  • 原文地址:https://www.cnblogs.com/iceicebaby/p/2418104.html
Copyright © 2011-2022 走看看