• [转]C# 邮箱验证激活


    原文链接

     /// <summary>
        /// 发送邮件 发送激活码
        /// </summary>
        /// <param name="address">接受者地址</param>
        /// <param name="displayName">接收者姓名</param>
        /// <param name="signString">激活码</param>
        public static void RegionSendEmail(string address, string displayName, string signString, string userName)//发激活码邮件部分
        {
            try
            {
    
                Encoding encoding = Encoding.GetEncoding("utf-8");
                Configuration config =
    WebConfigurationManager.OpenWebConfiguration("~/web.config");
                MailSettingsSectionGroup settings =
                    (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
                MailAddress from = new MailAddress(settings.Smtp.From, settings.Smtp.Network.UserName, encoding);
                MailAddress to = new MailAddress(address, displayName, encoding);
                MailMessage message = new MailMessage(from, to);
                message.SubjectEncoding = encoding;
                message.IsBodyHtml = true;
                message.Priority = MailPriority.High;
                message.Subject = "XXXXX邮箱验证激活";
                message.BodyEncoding = encoding;
                StringBuilder sb = new StringBuilder();
                sb.Append("您好:");
                sb.Append(userName);
                sb.Append("<br/>请点击下面的连接来验证激活");
                sb.Append(string.Format("<br/><a href='http://baidu.com/Index/CheckingEmailBack.aspx?SignString={0}&userName={1}'>", signString, userName));
                sb.Append(string.Format("http://baidu.com/Index/CheckingEmailBack.aspx?SignString={0}&userName={1}", signString, userName));
                sb.Append("</a>");
                //邮件主体
                message.Body = sb.ToString();
                //服务器
                SmtpClient client = new SmtpClient(settings.Smtp.Network.Host);
                //的用户名和密码
                client.Credentials = new NetworkCredential(settings.Smtp.From, settings.Smtp.Network.Password);
                client.Send(message);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

    我测试后无法成功, 这里特作两点说明 

    //要使用Configuration类,不仅要using System.Configuration; 还需要在引用中找到添加引用System.Configuration.dll
    //要使用WebConfigurationManager,不仅要System.Web.Configuration; 还需要在引用中找到添加引用System.Web.dll

  • 相关阅读:
    缓存技术2之CDN缓存 大风起
    Nginx入门级 大风起
    利用??运算符简化单件模式代码
    关于THREAD线程中CurrentCulture与CurrentUICulture的学习及疑问
    Lc.exe 已退出,代码 1
    家族荣誉
    检测到有潜在危险的Request.Form值
    FileUpLoad控件的使用
    ASP.NET中DataGrid和DataList控件用法比较
    漫谈DataList的用法
  • 原文地址:https://www.cnblogs.com/flyant/p/4277147.html
Copyright © 2020-2023  润新知