在load事件中引用sendmail方法~~经本人测试过~
private void Sendmail()
{
try
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add("106233153@qq.com");//这个是收件人的地址
msg.From = new MailAddress("xxxxx@163.com", "弟弟", System.Text.Encoding.UTF8);这个是发件人的地址
msg.Subject = "这是我自己写的发邮件的代码";//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = "<DIV> </DIV><DIV> </DIV><DIV> </DIV><div style='width:710px; margin:0 auto;'><div style='height:65px; border-bottom:2px solid #ccc;'><div style='float:left;'><img src=' http://www.oachina.com/images/logo.jpg' /></div><div style='float:right; margin-top:40px;'><a href=' http://www.oachina.com' target='_blank' style='color:#2b7be8;'>首页</a></div></div><DIV style='FONT-SIZE: 14px; MARGIN: 10px; LINE-HEIGHT: 40px'><DIV>亲爱的用户:</DIV><DIV>您好!</DIV><DIV>设置验证邮箱、设置密码保护问题将更好地保障您的帐号安全。</DIV><DIV>感谢您使用!</DIV><DIV>中办网个人中心</DIV><DIV>" + DateTime.Now.ToShortDateString() + "</DIV></DIV><div style='height:1px; background-color:#eaeaea;overflow:hidden; clear:both;'></div><DIV style='FONT-SIZE: 12px; TEXT-ALIGN: center; height:25px; line-height:25px;'>©OAchina</DIV></div>";//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = true;//是否是HTML邮件
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("xxxxx@163.com", "password");
client.Host = "smtp.163.com";
client.Send(msg);
Response.Write("发送Success");
}
catch (Exception e)
{
Response.Write("发送fail");
}
finally
{
Response.Write("发送了");
}
}