using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Mail; using System.Text; using System.Threading.Tasks; namespace OnlineExamination.Utility { public static class MailHelper { public static void SendMail(string titleText,string bodyText,params string[]targetMail) { //邮件主题内容 MailMessage mailMessage = new MailMessage();//注意:引用System.Net.Mail mailMessage.From = new MailAddress("***@qq.com", "显示名称"); for (int i = 0; i < targetMail.Length; i++) { mailMessage.To.Add(targetMail[i]); } mailMessage.Subject = titleText; mailMessage.Body = bodyText; //调用smtp服务器 SmtpClient client = new SmtpClient("smtp.qq.com"); client.Credentials = new NetworkCredential("账号", "密码"); client.Send(mailMessage); } } }