//产生随机数 private string sum() { Random rand = new Random(); string sums=""; for (int i = 0; i < 13; i++) { sums += rand.Next(0, 9).ToString(); } Ihouse.Model.UserInfo ucard = ubll.GetModelByCard(sums); if (ucard.Card == sums && ucard.Equals(sums)) { sum(); } return sums; } //邮件发送内容 private string contenttest(string card,string email){ string str = ""; string str1 = "<body><form id='form1' runat='server'><div style='background-image:url(/14d1acb2-84f3-42fe-9a69-5860e0343e38.jpg); width:771px; height:706px; margin:0px auto;'>"; string str2 = "<div style='width:590px; height:438px; padding-top:118px; padding-left:75px;'><ul style="list-style:none; line-height:30px;font-size:14px;" mce_style="list-style:none; line-height:30px;font-size:14px;">"; string str3="<li>"+email+"</li>"; string str4 = "<li style='background-image:url(c1a419f1-f1a9-4cb5-8ae2-47012ff7cca9.gif);background-repeat:repeat-x;margin-top:5px; height:3px; width:300px'></li>"; string str5="<li style="padding-left:20px;" mce_style="padding-left:20px;">您好:</li><li style="padding-left:40px;" mce_style="padding-left:40px;">以下是我公司发给您的购房卡号,您可凭此卡享受优惠活动,</li>"; string str6="<li style="padding-left:40px;" mce_style="padding-left:40px;">感谢您支 string str7 = "<li style="padding-left:40px;" mce_style="padding-left:40px;">祝您愉快! </li>"; string str8 = "<li style="padding-left:40px;" mce_style="padding-left:40px;"><div style='width:283px; height:159px;'>"; string str9 = "<div style='width:120px; height:15px;padding-top:88px; padding-left:45px; color:White; font-weight:bold;'>"; string str10=""+card+"</div></div></li><li></li>"; string str11="<li style="padding-left:250px; color:Red; font-size:16px; font-weight:bold;" mce_style="padding-left:250px; color:Red; font-size:16px; font-weight:bold;"><a href=''></a></li>"; string str12="</ul></div></div></form></body>"; str = str1 + str2 + str3 + str4 + str5 + str6 + str7 + str8 + str9 + str10 + str11 + str12; return str; } //发送邮件 private void FEmail(string email,string card) { //创建mailMessage对象 MailMessage mailmessage = new MailMessage(); mailmessage.From = "123456@163.com";//发件人 mailmessage.To = email;//收件人 mailmessage.Subject = "恭喜您注册成功-北京的购房卡";//主题 mailmessage.BodyEncoding = System.Text.Encoding.UTF8;//编码格式 mailmessage.Priority = MailPriority.Normal;//优先等级 mailmessage.BodyFormat = MailFormat.Html;//邮件格式 mailmessage.Body = contenttest(card,test1 .Value );//邮件内容 mailmessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",1); mailmessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "123456@163.com");//用户名(发件人) mailmessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "4564569");//密码(发件人) string meemail = "123456@163.com"; SmtpMail.SmtpServer = "smtp." + meemail.Substring(meemail.IndexOf("@")+1);//服务器(本地) try { SmtpMail.Send(mailmessage);//发送 } catch (Exception ex) { Response.Write("<mce:script language='javascript'><!-- alert('发送失败!!'"+ex.ToString()+"); // --></mce:script>"); } }