Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SSRS MHTML formatting problem when using gmail Expand / Collapse
Author
Message
Posted Monday, January 21, 2013 9:33 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, November 12, 2014 7:31 PM
Points: 78, Visits: 637
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
Post #1409613
Posted Thursday, April 4, 2013 4:58 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: 2 days ago @ 8:16 AM
Points: 450, Visits: 311
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?



Post #1438714
Posted Thursday, April 4, 2013 2:40 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, November 12, 2014 7:31 PM
Points: 78, Visits: 637
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;
}
}
}

Post #1439017
Posted Friday, April 5, 2013 1:34 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: 2 days ago @ 8:16 AM
Points: 450, Visits: 311
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.



Post #1439119
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse