public static void SendMail(string emsg)
{
string host = "smtp.163.com";
string username = "...@163.com";
string pwd = "....";
string formsb = "...";//接受
string fromcc = "...";//抄送
SmtpClient sc = new SmtpClient(host);
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.UseDefaultCredentials = true;
sc.Credentials = new System.Net.NetworkCredential(username, pwd);
string subject = "标题";
string body = "正文";
MailMessage msg = new MailMessage();
msg.From = new MailAddress(username, "程序提醒");
msg.To.Add(formsb);
if (!string.IsNullOrEmpty(fromsc))
msg.CC.Add(fromsc); //抄送人
msg.BodyEncoding = Encoding.UTF8;
msg.Subject = subject;
msg.Body = body;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.High;
try
{
sc.Send(msg);
Console.WriteLine("发送成功!");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}