MailMessage mail = new MailMessage(); //using System.Net.Mail;
mail.From = new MailAddress(“@163.com"); //发送人邮箱地址
mail.To.Add("@163.com”); //收件人邮箱地址
mail.Subject = name; //标题
mail.SubjectEncoding = Encoding.UTF8;
mail.Body = ex.ToString(); //正文
mail.Priority = MailPriority.High; //邮件优先级
mail.IsBodyHtml = true; //是否以HTML形式发送
SmtpClient smtpServer = new SmtpClient();
smtpServer.Host = “smtp.163.com”; //简单邮件传送协议服务器
smtpServer.Port = 25; //端口号
smtpServer.Credentials = new System.Net.NetworkCredential(“@163.com", "***********”); //账号密码
//smtpServer.EnableSsl = false;
try
{
//smtpServer.SendAsync(mail, “userToken”);//异步发送第二个参数时一个用户定义对象,此对象将被传递给完成异步操作时所调用的方法,参数默认即可
smtpServer.Send(mail); //同步发送
}
catch (Exception exa)
{
throw exa;
}