MailMessage msg = new MailMessage();
msg.To.Add("XXXX@qq.com");//添加收件地址
msg.From = new MailAddress("XXXXX@163.com", null, System.Text.Encoding.UTF8);//发送地址
msg.Subject = "这是测试邮件";//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = "邮件内容";//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = false;//是否是HTML邮件
msg.Priority = MailPriority.High;//邮件优先级
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("XXXXX@163.com", "XXXXX");//身份验证
//邮箱的SMTP
client.Host = "smtp.163.com";
object userState = msg;
try
{
client.Send(msg);
return true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}