private bool send(string to,string body)
{
// using System.Net.Mail;
MailMessage message = new MailMessage();
message.From = new MailAddress(test@test.com, "Test Error Sender");
message.To.Add(new MailAddress(to)); // the email you want to send email to
message.Subject = "Test Error Monitor";

message.IsBodyHtml = true;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Body = body;
message.Priority = MailPriority.High;

SmtpClient client = new SmtpClient("smtp.gmail.com", 587); // 587是Gmail使用的端口
client.Credentials = new System.Net.NetworkCredential("test@gmail.com", "123456"); // Your user name & password
client.EnableSsl = true; //经过ssl加密
object userState = message;
try
{
client.Send(message);
//Response.Write("邮件发送到" + message.To.ToString() + "<br>");
return true;
}
catch (Exception ee)
{
ee.ToString();
return false;
//Response.Write(ee.message + "<br>" + ee.InnerException.message);
}
return true;

}
posted on 2011-09-06 22:22  小伟地方  阅读(170)  评论(0编辑  收藏  举报