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);
        }
    }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值