Exemple #1
0
 public static MailMessage AddHtmlView(this MailMessage mail, string htmlBody, List <string> resources, IResourceResolver resourceResolver)
 {
     if (mail != null && htmlBody.Clear() != null && resources != null && resources.Any())
     {
         if (resourceResolver == null)
         {
             throw new Exception("ResourceResolver not set");
         }
         AlternateView av = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);
         resources.ForEach(r =>
         {
             HtmlResource hr = resourceResolver.GetHtmlResource(r);
             if (hr != null)
             {
                 MemoryStream ms = new MemoryStream(hr.Content);
                 LinkedResource lr;
                 if (hr.MediaType.Clear() != null)
                 {
                     lr = new LinkedResource(ms, hr.MediaType.Clear());
                 }
                 else
                 {
                     lr = new LinkedResource(ms);
                 }
                 lr.ContentId = hr.ContentId;
                 av.LinkedResources.Add(lr);
             }
             mail.AlternateViews.Add(av);
         });
     }
     return(mail);
 }
Exemple #2
0
 public static MailMessage AddHtmlView(this MailMessage mail, string htmlBody, List<string> resources, IResourceResolver resourceResolver)
 {
     if (mail != null && htmlBody.Clear() != null && resources != null && resources.Any())
     {
         if (resourceResolver == null)
         {
             throw new Exception("ResourceResolver not set");
         }
         AlternateView av = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);
         resources.ForEach(r =>
         {
             HtmlResource hr = resourceResolver.GetHtmlResource(r);
             if (hr != null)
             {
                 MemoryStream ms = new MemoryStream(hr.Content);
                 LinkedResource lr;
                 if (hr.MediaType.Clear() != null)
                 {
                     lr = new LinkedResource(ms, hr.MediaType.Clear());
                 }
                 else
                 {
                     lr = new LinkedResource(ms);
                 }
                 lr.ContentId = hr.ContentId;
                 av.LinkedResources.Add(lr);
             }
             mail.AlternateViews.Add(av);
         });
     }
     return mail;
 }