注意用服务发送邮件 360安全卫士会拦截,调试程序时也不会报异常,大家要小心

MailMessage mail = new MailMessage();
mail.Subject = "主题,如xxx";
mail.From = new MailAddress("xxx.xxx@xxx.cn", "xxx");
mail.To.Add(new MailAddress("xxx@xxx.xx", "xx")); //可以添加多个收件人
mail.CC.Add(new MailAddress("xx@xxx.cn", "xx")); //抄送
mail.Body = "测试邮件";
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = false;
mail.Priority = MailPriority.High;

SmtpClient smtp = new SmtpClient("xxx.xxxx.com", 25);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("usrname", "password"); //通行证
smtp.DeliveryMethod = SmtpDeliveryMethod.Network; //递送方法为 网络
smtp.Send(mail);