Example #1
0
        protected void ConvertToImage(MailMessage message)
        {
            var datePrefix = DateTime.UtcNow.ToString("yyyyMMddHHmmss");
            var typePrefix = GetType().Name.ToLower().Replace(".", "");

            System.Drawing.Image image = null;
            var byteStream             = RIFF.Interfaces.Formats.HTML.RFHTMLRenderer.Render(message.Body, out image);

            if (byteStream != null && byteStream.Length > 0)
            {
                if (image.Height > 1000) // auto-split long images into parts
                {
                    var images = new List <Image>();
                    var bitmap = new Bitmap(image);
                    for (int i = 0; i < image.Height; i += 1000)
                    {
                        var imagePart = bitmap.Clone(new Rectangle {
                            X = 0, Y = i, Width = image.Width, Height = Math.Min(1000, image.Height - i)
                        }, System.Drawing.Imaging.PixelFormat.DontCare);
                        if (imagePart != null)
                        {
                            var tag = String.Format("Image{0}{1}{2}", datePrefix, typePrefix, i);
                            imagePart.Tag = tag;
                            images.Add(imagePart);
                        }
                    }
                    RenderImageList(images, message, null, null);
                }
                else
                {
                    var imageAttachment = new Attachment(new MemoryStream(byteStream), "Image.png", "image/png");
                    imageAttachment.ContentId = "Image";
                    message.Attachments.Add(imageAttachment);
                    message.Body = RFRazor.RunTemplate(typeof(ImageEmail), image);
                }
            }
            else
            {
                throw new RFSystemException(this, "Unable to reder email to image.");
            }
        }
Example #2
0
 protected void RenderImageList(List <Image> images, MailMessage message, string headerHTML = null, string footerHTML = null)
 {
     foreach (var image in images)
     {
         using (var memoryStream = new MemoryStream())
         {
             image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
             var bytes           = memoryStream.ToArray();
             var tag             = image.Tag.ToString();
             var imageAttachment = new Attachment(new MemoryStream(bytes), tag + ".png", "image/png");
             imageAttachment.ContentId = image.Tag.ToString();
             message.Attachments.Add(imageAttachment);
         }
     }
     message.Body = RFRazor.RunTemplate(typeof(ImageListEmail), new RFImageListEmailModel
     {
         Images     = images.ToArray(),
         HeaderHTML = headerHTML,
         FooterHTML = footerHTML
     });
 }
Example #3
0
 protected virtual string GenerateBody()
 {
     return(RFRazor.RunTemplate(typeof(T), this));
 }