Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SSRS MHTML formatting problem when using gmail


SSRS MHTML formatting problem when using gmail

Author
Message
brickpack
brickpack
SSC Journeyman
SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)

Group: General Forum Members
Points: 86 Visits: 929
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
singhster
singhster
SSC-Addicted
SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)

Group: General Forum Members
Points: 456 Visits: 344
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?



brickpack
brickpack
SSC Journeyman
SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)

Group: General Forum Members
Points: 86 Visits: 929
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;
}
}
}


singhster
singhster
SSC-Addicted
SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)

Group: General Forum Members
Points: 456 Visits: 344
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.



richard.little
richard.little
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 8
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]
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search