这东西,不关MVC的事。
发送邮件,有个是内容的参数,每次讲这个参数设置为动态的就行了,其他的都一样
群发,就是把接收地址列表遍历一下,把每一个都发一下,就变成了群发.
/// <summary> /// 发送邮件,附加附件 /// </summary> /// <param name="excelPath">附件地址</param> /// <returns></returns> public static bool SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody) { try { System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer); client.Timeout = 9999999; client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass); client.DeliveryMethod = SmtpDeliveryMethod.Network; System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(strFrom, strto, strSubject, strBody); //System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(excelPath); //message.Attachments.Add(attachment); message.BodyEncoding = System.Text.Encoding.UTF8; message.IsBodyHtml = true; client.Send(message); } catch (Exception ex) { return false; } return true; }
这和MVC关系不大,定义一个消息类(发送人,收件人,内容,附件等),遍历这样的一个数组或者List,每次发送一封邮件,就是群发了。
发的数量多了就是群发了·