SSRS MHTML formatting problem when using gmail

  • Hello...

    I'm not finding any resolutions to a problem that many seem to be running into. Google searches are turning up more questions than answers. I'm hoping someone here can help me.

    I found a really annoying problem when using the MHTML (web archive) report rendering option in SSRS 2008 R2. When a report is emailed out as a web archive and viewed using gmail webmail, all of the special formatting, tables and all, are stripped out of the email body. When the same report is viewed using Outlook or Mac Mail, the formatting works and the report looks great.

    Last week I spent hours creating a new report and was asking for feedback from my boss (gmail webmail user) about how the report looked. I couldn't understand why he wasn't very excited about the report until I realized that he'd been using webmail to view the report and all of the formatting was completely stripped out. I had been using Outlook during development...so I had no idea how bad it looked in webmail.

    The question now is...how can I deliver this report embedded in the body of an email with the formatting intact using SSRS...? He doesn't want the report delivered as an attachment.

    Thanks

  • Hi,

    I'm having the same issue I'm afraid. All I see is a "Message Clipped" message in gmail, and the mhtml is only 13KB so I wouldn't expect it to be. I don't suppose you found a resolution to this problem?

  • I was able to hack it all together with C#.

    The following assumes that you know a little bit about using Visual Studio and programming in C#.

    1) Create a subscription in SSRS that saves the report locally to the server as HTML 4.0

    2) Create a new C# project using Visual Studio Express 2010 or 2012

    3) Install NuGet package manager and then get PreMailer from http://nuget.org/packages/PreMailer.Net/1.1.2

    4) You'll see in the code that I had to add some Regex.Replace statements to the method in order to clean up and reduce the size of my report. You might not need these because your report is small.

    5) Schedule a task that runs the .exe from the complied C# code.

    It's not pretty...but it works... Good Luck!

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Threading.Tasks;

    using System.Windows.Forms;

    using System.Net.Mail;

    using System.Net;

    using System.Text.RegularExpressions;

    using System.IO;

    namespace Report

    {

    static class Program

    {

    /// <summary>

    /// The main entry point for the application.

    /// </summary>

    [STAThread]

    static void Main()

    {

    var content = File.ReadAllText(@"D:\Report\Report.html");

    var pm = new PreMailer.Net.PreMailer();

    string premailedOutput = pm.MoveCssInline(content, false);

    var content2 = Regex.Replace(premailedOutput, @"<style.*</style>", @"", RegexOptions.Singleline);

    content2 = Regex.Replace(content2, @"<!\[CDATA\[.*?\]\]>", @"", RegexOptions.Singleline);

    content2 = content2.Replace("border-bottom: 1pt solid black;border-left: 1pt solid black;border-right: 1pt solid black;border-top: 1pt solid black", "border: 1pt solid black");

    content2 = content2.Replace("padding-bottom: 2pt;padding-left: 2pt;padding-right: 2pt;padding-top: 2pt", "padding: 2pt");

    content2 = content2.Replace("text-decoration: none;unicode-bidi: normal;vertical-align: middle;white-space: pre-wrap;word-wrap: break-word;writing-mode: lr-tb;", "");

    List<string> emailList = new List<string>()

    {

    "emailaddr1@domain.com", "emailaddr2@domain.com", "emailaddr@domain.com"

    };

    var email = SendMail("noreply@domain.com", emailList, "Daily Report", content2, true, null);

    }

    public static bool SendMail(string from, List<string> to, string subject, string body, bool bodyIsHtml, Dictionary<string, Stream> attachments)

    {

    try

    {

    var message = new System.Net.Mail.MailMessage();

    message.From = new System.Net.Mail.MailAddress(from);

    to.ForEach(new Action<string>(message.To.Add));

    message.Subject = subject;

    if (bodyIsHtml)

    message.AlternateViews.Add(System.Net.Mail.AlternateView.CreateAlternateViewFromString(body, new System.Net.Mime.ContentType("text/html")));

    else

    message.Body = body;

    message.Body = Regex.Replace(message.Body, "[^\r]", "\r");

    if (attachments != null)

    {

    foreach (var attachment in attachments)

    {

    message.Attachments.Add(new System.Net.Mail.Attachment(attachment.Value, attachment.Key));

    }

    }

    var smtp = new System.Net.Mail.SmtpClient("someOpenMailRelay.com", 25);

    smtp.Credentials = new NetworkCredential("username", "password");

    smtp.Send(message);

    }

    catch (Exception ex)

    {

    var toString = ex.ToString();

    return false;

    }

    return true;

    }

    }

    }

  • Wow, thanks BrickPack, that's really useful!

    Unfortunately, I'm attempting to get some Business Intelligence folk (non-developers) to create and email reports to themselves using Report Builder. Looks like it's a problem at gmail's end though, as it renders better on my iphone than gmail.

    Thanks for your detailed response though.

  • Hi. I experienced the same when our company migrated to gmail, however, developed a solution that is straightforward.

    All you need to do is add a parameter for each element. For example, to change the fill colour simply add a parameter and change the Default Value to the desired colour (eg #code or colour name). Set the parameter to Hidden prevents the user from seeing it when the report is run.

    For borders, same concept except you need to add the colour (eg black), width (eg 1Pt) and style (eg Solid).

    Hope this helps! [Richard Little]

  • Adding a parameter for the border around the image (logo) did NOT work.  Yeash.  What can we do to get Microsoft to pay attention to the fact that they have eliminated one of the basic export capabilities by ignoring this stupid issue?  I REALLY want to know either how to fix this without coding.  Maybe there's a newer version of that export available that we can install or something. Good grief.  This is plain unacceptable.

  • Karen Grube - Thursday, August 16, 2018 10:28 PM

    Adding a parameter for the border around the image (logo) did NOT work.  Yeash.  What can we do to get Microsoft to pay attention to the fact that they have eliminated one of the basic export capabilities by ignoring this stupid issue?  I REALLY want to know either how to fix this without coding.  Maybe there's a newer version of that export available that we can install or something. Good grief.  This is plain unacceptable.

    To be honest, retrieving an SSRS report using a gmail account is a LOT closer to unacceptable.  Handing that entire report to Google is about as unsecure as you can get.   I wouldn't even consider allowing such to occur.   Convenience and security just don't go hand in hand, and until the users are educated to the point where they understand AND agree with that reasoning, they shouldn't have access to diddly-squat.   I tire of the excuses people offer for avoiding their security responsibilities.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply