using System.Net;
using System.Net.Mail;
System.Random rd = new Random();
int val = rd.Next(999999, 100000000);
HttpCookie a = new HttpCookie("registercodeyc", val.ToString());
Response.Cookies.Add(a);
#region 发送邮件到用户邮箱
try
{
string to = this.txtEMail.Value;
string from = "
ycceo99@sohu.com";
MailMessage message = new MailMessage(from, to);
message.SubjectEncoding = System.Text.Encoding.Default;
message.BodyEncoding = System.Text.Encoding.Default;
message.Subject = "**注册验证";
message.Body = this.txtName.Value + "您好! 您**的注册验证码:" + val.ToString() + " 请勿回复!";
SmtpClient client = new SmtpClient("smtp.sohu.com");
client.Port = 25;
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
//client.UseDefaultCredentials = true;
client.Credentials = new NetworkCredential("用户名", "密码");
client.Send(message);
Response.Write(clsFun.MessageInfo("邮件发送成功,请到您的邮箱里查看注册验证码,谢谢!"));
}
catch
{
Response.Write( clsFun.MessageInfo("邮件发送失败!请查看您的邮箱地址是否正确"));
}
#endregion
因163.yahoo.hotmail.等不支付smtp.不能发送,sohu的可以.sina的我没试.
把因引用了.把代码考过去就能用.