- C# code
protected void Button1_Click(object sender, EventArgs e) { MailAddress MessageFrom = new MailAddress("sender@163.com"); //发件人邮箱地址 if (Send(MessageFrom, "receiver@163.com", "找回密码", "您的密码是:78910")) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "alert", "<script>alert('发送邮件成功!');this.location='Login.aspx'</script>", false); } else { Response.Write("发送邮件失败"); } } /// <summary> /// 发送电子邮件 /// </summary> /// <param name="MessageFrom">发件人邮箱地址</param> /// <param name="MessageTo">收件人邮箱地址</param> /// <param name="MessageSubject">邮件主题</param> /// <param name="MessageBody">邮件内容</param> /// <returns></returns> public bool Send(MailAddress MessageFrom, string MessageTo, string MessageSubject, string MessageBody) { MailMessage message = new MailMessage(); message.From = MessageFrom; message.To.Add(MessageTo); //收件人邮箱地址可以是多个以实现群发 message.Subject = MessageSubject; message.SubjectEncoding = Encoding.GetEncoding(936); message.Body = MessageBody; message.BodyEncoding = Encoding.GetEncoding(936); message.IsBodyHtml = false; //是否为html格式 message.Priority = MailPriority.High; //发送邮件的优先等级 SmtpClient sc = new SmtpClient(); sc.DeliveryMethod = SmtpDeliveryMethod.Network; //将smtp的出站方式设为 Network sc.EnableSsl = false;//smtp服务器是否启用SSL加密 sc.Host = "smtp.163.com"; //指定发送邮件的服务器地址或IP sc.Port = 25; //指定发送邮件端口 sc.Credentials = new System.Net.NetworkCredential("sender@163.com", "123456"); //指定登录服务器的用户名和密码(发件人的邮箱登陆密码) try { sc.Send(message); //发送邮件 } catch { return false; } return true; }
这样试过多次都提示发送失败,也没其他错误提示,求解
------解决方案--------------------------------------------------------