Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 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;
 }