致力于技术进步

专注于编程艺术

博客园 首页 新随笔 联系 订阅 管理

 try
                {
                    int USER_ID = 8;
                    MailMessage mailMsg = new MailMessage();
                    mailMsg.To = "zhoujingen@yeah.net";//user.USER_EMAIL;
                    mailMsg.From = ConfigurationManager.AppSettings["MailServerFrom"].ToString();
                    mailMsg.Subject = "安徽教育网台找回密码确认";
                    //authorization是UserID和服务端时间的组合加密串,修改密码前将对授权串和时间戳进行验证。
                    string authorization = Utils.MD5(USER_ID + DateTime.Now.ToString());
                    string validationQueryString = String.Format("UserID={0}&Time={1}&Authorization={2}", USER_ID, DateTime.Now.ToString(), authorization);
                    validationQueryString = Utils.GetBase64String(validationQueryString);

                    string validation = ConfigurationManager.AppSettings["ModifyPsw"].ToString() + String.Format("?Validation={0}", validationQueryString);
                    mailMsg.Body = "尊敬的安徽热线用户,您好:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请点击下面的链接修改您的密码<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='" + validation + "'>点击修改密码</a>";
                    mailMsg.BodyFormat = MailFormat.Html;//设置为HTML格式      
                    //设置为需要用户验证    
                    mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
                    //设置验证用户名   
                    mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", ConfigurationManager.AppSettings["MailServerUserName"].ToString());
                    //设置验证密码)    
                    mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", ConfigurationManager.AppSettings["MailServerPassword"].ToString());
                    SmtpMail.SmtpServer = ConfigurationManager.AppSettings["MailServerAddress"].ToString();     //邮件服务器地址(mail.iflytek.com)    
                    SmtpMail.Send(mailMsg);
                }
                catch (Exception ex)
                {
                    Response.Write("邮件发送失败,原因:" + ex.Message.ToString());
                }

posted on 2009-11-20 14:43  stephen&amp;#183;周  阅读(248)  评论(0编辑  收藏  举报