Shrink SSRS HTML5 rendered document size for gmail

I have a C# app that generates SSRS Reports which are either attached to an email or added to the body of the message if the rendering format is HTML. Emails are looking great and then someone opens it in the gmail web client and sees a nasty [message clipped] message, turn outs gmail clips the contents of an email body if it is bigger than 105kb.

After reviewing some documentation, https://docs.microsoft.com/en-us/sql/reporting-services/report-builder/rendering-to-html-report-builder-and-ssrs, I noticed that the rendering engine will render both a full HTML and fragmented HTML document. Wouldn’t you know it the fragmented version is much smaller, all styling is inline and not so bloated with javascript.

I render my reports using the ReportExecutionService class which contains a method called Render; Render accepts a DeviceInfo parameter that when set to null gives you the full HTML document, however if you set the value of DeviceInfo to   @"<DeviceInfo><StreamRoot>/</StreamRoot><HTMLFragment>True</HTMLFragment></DeviceInfo>" you get a fragmented small html file that renders in gmail perfectly.

The code snippet below provides a simple inline if statement to set the value

string deviceInfo = format == "HTML5" ? @"<DeviceInfo><StreamRoot>/</StreamRoot><HTMLFragment>True</HTMLFragment></DeviceInfo>" : null; 

Advertisements