玩玩樂樂

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 /// <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);
        }
    }

 


posted on 2011-11-02 15:24  刘剑_1989  阅读(930)  评论(0编辑  收藏  举报