public static MailMessage AddAttachments(this MailMessage mail, List <string> attachments, IResourceResolver resourceResolver) { if (mail != null && attachments != null && attachments.Any()) { if (resourceResolver == null) { throw new Exception("ResourceResolver not set"); } attachments.ForEach(a => { MailAttachment att = resourceResolver.GetMailAttachment(a); if (att != null) { MemoryStream ms = new MemoryStream(att.Content); if (att.MediaType.Clear() != null) { mail.Attachments.Add(new Attachment(ms, att.Name, att.MediaType)); } else { mail.Attachments.Add(new Attachment(ms, att.Name)); } } }); } return(mail); }
public static MailMessage AddAttachments(this MailMessage mail, List<string> attachments, IResourceResolver resourceResolver) { if (mail != null && attachments != null && attachments.Any()) { if (resourceResolver == null) { throw new Exception("ResourceResolver not set"); } attachments.ForEach(a => { MailAttachment att = resourceResolver.GetMailAttachment(a); if (att != null) { MemoryStream ms = new MemoryStream(att.Content); if (att.MediaType.Clear() != null) { mail.Attachments.Add(new Attachment(ms, att.Name, att.MediaType)); } else { mail.Attachments.Add(new Attachment(ms, att.Name)); } } }); } return mail; }