C#SMTP发邮件

public static bool SendMailUse()
{
string host = "smtp.163.com";// 邮件服务器smtp.163.com表示网易邮箱服务器
string userName = "enbqluqib59@163.com";// 发送端账号
string password = "a96606";// 发送端密码(这个客户端重置后的密码)

SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式
client.Host = host;//邮件服务器
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential(userName, password);//用户名、密码

string strfrom = userName;
string strto = "llun96202@sina.com";
//string strcc = "llun96202@sina.com";//抄送


string subject = "订单标题";//邮件的主题
string body = "订单标题";//发送的邮件正文

System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = new MailAddress(strfrom, "订单");
msg.To.Add(strto);
//msg.CC.Add(strcc);

msg.Subject = subject;//邮件标题
msg.Body = body;//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = true;//是否是HTML邮件
msg.Priority = MailPriority.High;//邮件优先级

try
{
client.Send(msg);
return true;
}
catch (System.Net.Mail.SmtpException ex)
{
return false;
}
}

posted @ 2018-02-17 22:23  net668  阅读(238)  评论(0编辑  收藏  举报