Free Support Forum - aspose.com

Will Aspose.Email help with my Outlook HTML formatting

I am doing research on an issue and came across Aspose.Email which seems like it might be able to help me, but I can’t nail it down in the documentation, so I thought I would post my issue here to find out for sure.


I am using an automated testing application called Ranorex that outputs log files as XML and provides an .xsl file to do the transform. When I open the XML file in IE, it formats properly, has some Javascript UI elements and is very useful. I wrote an app that will do this transform in C# and then put the HTML in the body of an email to be sent out to the company where we all use Outlook. Of course the formatting is completely off and unusable, and I get the little message at the top of the email to click to open the message in a browser which is not ideal.

I am wondering if I can use the Aspose.Email library and use my same XML or the HTML and then render it properly so it looks correct in Outlook. If this is possible, if you could point me to a sample of this or some documentation, that would be great.

Hi Ryan,


Thank you for considering Aspose.Email.

You can set an email’s body with HTML contents by using the MailMessage’s HtmlBody property. The HtmlBody can be set directly as shown in the following code line, or from a string variable that contains the complete HTML contents.

message.HtmlBody = “This is the HTML body”;

I would request you to please have a look at the Sending a Simple HTML email article from our documentation.

In addition, you can use Aspose.Email along with our Aspose.Cells component to convert an Excel file to HTML and write the HTML to the message’s body. We have such an Example available in our documentation section for your reference.

I hope these articles will give you enough space to test your requirements using Aspose.Email API. But if you still need further assistance in this regard, feel free to contact us. We will be glad to help you as soon as possible.

PS: I would recommend you to always use the latest version of Aspose.Email (currently it is Aspose.Email for .NET 2.5.0 and Aspose.Email for Java 2.5.0) in your applications, as we do monthly product releases for various bug fixes and, may be, enhancements/new features.

Thanks for the response. To clarify my question, I am aware that Aspose can send HTML formatted email, what I am asking is around Outlook formatting. It is known that Outlook (2007 and later) uses Word for its HTML rendering instead of IE. This causes a lot of issues for designers/developers who need to create HTML formatted emails that format properly in Outlook as well as other email clients.


I am running into this same issue. I have HTML that I can put into the regular C# System.Net.Mail.MailMessage object and send out an email from my application. The email message looks perfect on my Android phone email client because it renders it using WebKit, however that same email in Outlook looks horrible. The images are missing, the formatting is all messed up, etc.

So, my original question was, is there anything in Aspose.Email that will help facilitate the process of creating email messages that are properly formatted when viewing them from Outlook. I spent the morning downloading Aspose.Email and added it to my project and tried it out, and I am not seeing anything to facilitate this. This is a common problem in the industry (there are tons of posts about it), but as far as I know, no one has a library to help with this. I think everyone just rolls their own transform to format their email (which I guess is what we will do). Aspose should look into this as a possible product. I know we would pay for such a product :slight_smile:

Hi Ryan,


Could you please send us some sample HTML files and converted messages that we can use to analyze this issue? We will look into this and try to assist you further by consulting our development team in this regard.

Sure. I have attached Example.zip which contains 2 files, LoginLogout20121203171454.rxlog which is my XML file and RanorexReport3.xsl which is the transform file.


In my C# code, I use this (condensed for this post) to create the HTML using the two files.

var myXsl = new StreamReader(C:\temp\RanorexReport3.xsl);
var xsltString = “”;
xsltString = myXsl.ReadToEnd();
myXsl.Close();

var inputXml = “”;
var myXml = new StreamReader(C:\temp\ LoginLogout20121203171454.rxlog);
inputXml = myXml.ReadToEnd();
myXml.Close();


var transform = new XslCompiledTransform();
using (var reader = XmlReader.Create(new StringReader(xsltString)))
{
transform.Load(reader);
}
var results = new StringWriter();
using (var reader = XmlReader.Create(new StringReader(inputXml)))
{
transform.Transform(reader, null, results);
}

Once I have my HTML, I send out my email using the code below. I swapped out this code with the Aspose.Email code this morning to play around with the formatting, but I have since deleted it. The two essentially do the same thing…create a message, create an SMTPClient and then send out the email. When the email is sent out it looks fine in email clients that use something like a Webkit rendering engine, but look really bad in Outlook 2007 and beyond. Getting the formatting to look good in Outlook is what I am trying to achieve.

var md = new MailDefinition();
md.From = "noreply@somecompany.com";
md.IsBodyHtml = true;
md.Subject = “Test Suite has completed” ;

var replacements = new ListDictionary();

MailMessage msg = md.CreateMailMessage(, replacements, body, new Control());

var client = new SmtpClient(“smtpserver.somecompany.com”);
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(msg);

Hi Ryan,


Thank you for the supporting material.

I tried this issue with the help of your provided files and was able to observe the issue that you mentioned. Apparently, it seems to be an issue at the Outlook end (mentioned by you as well), as Aspose.Email is just sending the email. I couldn’t find any such option/information from Aspose.Email’s point of view that could help in this situation. However, I will discuss these findings with the development team to see if there could be anything done in this regard, and will update you then via this thread.

Hi Ryan,


Hope you be doing good.

This is just to let you know that we haven’t forgotten you. I have already forwarded your provided details to our development team under issue id: NETWORKNET-33640 to sought their opinion in this regard. As soon as there is some information available, I’ll update you via this thread, and appreciate your patience till then.

Hi Ryan,


Our development team has analyzed the issue in detail and they have informed that HTML adjustment for its correct display in Outlook is
beyond the scope of Aspose.Email (AE). This is the problem of Outlook but not AE.

<o:p></o:p>

Also your HTML example contains much of javascript code and it is worth to take into account that none of the e-mail clients will display it in the same way as it is in browsers.

Thanks for your patience and understanding in this regard.