如下代码:
string mail = txtMail.Text;
Random rd = new Random();
string newPassword=rd.Next().ToString();
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.163.com";
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("[email protected]","qiye1985");
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("[email protected]", "[email protected]");
message.Subject = "找回密码";
message.Body = "您的用户名:"+user.UserId+"您的新密码:" + newPassword;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
user.PassWord = newPassword;
UserInfoManager.ModifyUserInfo(user);
client.Send(message);
txtValidate.Text = "";
this.post.Visible = true; 运行后,当我按忘记密码时,跳出窗口填写邮件地址和密码,按提交时报错:邮箱不可用。 服务器响应为: Óû§±»Ëø¶¨
什么原因?望高手指教
using System.Net.Mail;//发送过程
//发送邮件类
//发送邮件类
MailMessage mail = new MailMessage();
//第一个是发送人邮件,第二个是个标签
mail.From = new MailAddress("[email protected]", "Halie"); //发送给谁
mail.To.Add("[email protected]");
//发送内容
mail.Body = "<html><body>"+"ss"+"</body></html>";
//发送内容的编码方式
mail.BodyEncoding = System.Text.Encoding.UTF8;
//邮件的优先级
mail.Priority = MailPriority.Normal;
//邮件标题
mail.Subject = "标题";
//邮件标题的编码方式
mail.SubjectEncoding = System.Text.Encoding.UTF8; //创建一个client服务器
SmtpClient sc = new SmtpClient();
//第一个为发送邮件名,第二个为发送邮件密码
ICredentialsByHost ic = new NetworkCredential("jing87898797", "******"); //jing87898797为你发送邮箱的账号,不加@163.com后缀 //******为发送邮箱密码
sc.Host = "smtp.163.com";//这边必须和发送邮箱的同类型:163-smtp.163.com 126-smtp.126.com
//常用
sc.Port = 25;
sc.Credentials = ic;
//发送邮件
sc.Send(mail);