HTML not displaying correctly in outlook 2007 emails? - c#

EDITED:
I have written some correct HTML and passed this as a string into an email,
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>/n<html>
<head>
</head>
<body>
<table>
<tr>
<th>X</th>
<th>Y</th>
</tr>
<tr>
<td>Overall</td>
<td>207,890</td>
</tr>
<tr>
<td>a</td>
<td>100,568</td>
</tr>
<tr>
<td>b</td>
<td>107,322</td>
</tr>
</table>
</body>
</html>
I re-wrote the HTML to be extremely simple, only using a table but its still not showing??

Generally email clients don't seem to like decently formatted HTML. Just from conversation I've had with HTML developers
Use inline styles even if that means repeating yourself. No style sheets even in head
No fancy floating of the divs
Put everything in tables for formatting
Generally pretend like it's 1999

Your problem is probably not only Outlook 2007 but most other email clients as well.
Make sure that your html is very simple and does not use many external resources, inline CSS is probably necessary. This article is a nice summary: http://css-tricks.com/using-css-in-html-emails-the-real-story/

Related

How to build HTML Table dynamically as template for sending email (ng-repeat)

Currently I build HTML templates and replace {Title} placeholder with matching values before sending 'parsed email template' to recipients but the issue is there's no way to generate 'list of data' in table dynamically, thus resorting to using angularjs 'ng-repeat' but when parsed, it sends out angularjs tags instead of generating the HTML representation
My question is how can I build 'angularjs' template with ng-repeat that can be used for sending email templates dynamically without having to load the page in browser cause it seems the angularjs page is only translated when opened in browser
How is it possible using ng-repeat to generate HTML tags dynamically, suitable enough to be sent as email message, thanks
{Title} Placeholder
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
It's not directly possible with angularjs, but it's supported with angular 2+ (using nodejs on server: https://angular.io/guide/universal ).
I had an identical need and I remember attempts to achieve what you want using angularjs running on server in selenium webdriver but I couldn't find a complete and easy solution.
Instead, I copied my ng-repeat templates and converted them to very simple asp.net razor templates, and I pass my json model as dynamic ViewModel.
I know it's not angularjs but it's a good serverside alternative and you tagged c# too.
Example template:
#Model dynamic
<h4>#Model.Title</h4>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
#foreach (dynamic x in Model.Students)
{
<tr>
<td>#x.FirstName</td>
<td>#x.LastName</td>
<td>#x.Age</td>
</tr>
}
</table>
You can use the RazorEngine nuget to help generate the output: http://antaris.github.io/RazorEngine/

split a dynamic generated HTML files

My application converts several types of documents into HTML files. Then, it exposes generated files to users or search engine robots.
My problem is that some documents contain more than 100 pages and the generated HTML file is huge.
I am looking for a way to split HTML files into several pages.
One possible solution is split them by size and number of characters which is a tough solution because we should consider the style of HTML files.
For example, consider following HTML file:
<p>
-- So long paragraph with more than 100 lines
</p>
<table>
<tr>
<td> </td>
</tr>
...... more than 10 rows
</table>
the split mechanism should create several files for the paragraph and also, it should create one file for the table. like following:
PAGE1.HTML
<p>
-- contains 20 lines of original text
</p>
PAGE2.HTML
<p>
-- contains 20 lines of original text
</p>
PAGE3.HTML
<p>
-- contains 20 lines of original text
</p>
...
PAGE6.HTML
<p>
<table>
<tr>
<td> </td>
</tr>
...... more than 10 rows
</table>
</p>
please advice me, if you know a better solution or tools for achieving the solution?
You have to disentangle content from the HTML. If you opt for an intermediate format, that you control, you can generate HTML files with appropriate amount of content.
Trying to cut it after the HTML is generated is worse option, and inefficient one. You can try and navigate the HTML document using (e.g.) HtmlAgilityPack, but without intimate knowledge of what elements in what structure you actually generate it's hard to pinpoint the way of actually performing the split - and again, it will be much harder than splitting the content before it becomes HTML.

Retrieving html data from database to create a page

I have stored html file in database. Now I would like to get data using cs file and link it to my view page. Below is my example of how I have save my able.
My database table contains two columns (page_header, page_footer).
page_header
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
page_footer
<footer>
<table width="100%">
<tr>
<td>
Written by Jon Doe.<br>
Visit us at:<br>
Example.com<br>
Box 564, Disneyland<br>
USA
</td>
<td>
Visit our Site
</td>
</footer>
I want to retrieve those data to my aspx page. Can anyone help in doing that. Or if any demo is available which will be helpful understand how to do that.
If this post is not related please don't degrade. Just let me know, I will delete it.
This is how you get user-specific information to your user without having to hand-update every single page you ever serve:
<!DOCTYPE html>
<html>
<head>
<title runat="server">Page Title</title>
</head>
<body runat="server">
<div id="welcomeDiv" runat="server"></div>
<div id="dataDiv" runat="server">
<datagridview id = "customerData" runat="server">
</div>
</body>
</html>
then, in your codebehind file:
private void Form1_Load(object sender, EventArgs e)
{
//load name from db
Form1.Title = "Welcome back, Mr. "+customer.LastName;
welcomeDIV.InnerHtml = "<b>It's been "+customer.daysSinceLastVisit.ToString()+" days since you last visited! How are "+customer.wifeName+" and the boys?</b>";
customerData = loadDataGrid(customer.ID);
}
It seems that you are creating some kind of a multi-tenant system and need a small amount of customization for each tenant.
There is no reason not to store HTML templates in a database—CMSes such as Wordpress do that a lot. However, to #ShannonHolsinger's point, you should ensure that your database schema is normalized to a reasonable extent. Consider storing e-mail address, contact name, address and website URL as separate fields.
For a templating system, there are many types of choices. You should explore some so you can choose one that is most familiar to you or your needs. In every case, though, be sure that data is property escaped to HTML or you could be allowing your page to be taken over. If you just paste strings together, such as by using InnerHtml then someone could enter their name as </div><script>ChangeTheEntirePageToWhatEverILike()</script> or </div><script>InjectInSomeCodeToSendFormDataToMySite()</script> and it would be seen by the browser as your code rather than as text.
One templating technique could involve client-side data binding. Some popular libraries are Knockout and Angular 2. For client-side data binding, you could put variable references in trusted header and footer HTML and then pass the variable values to be bound as JavaScript data. In other words, let the browser do any data merging that's needed rather than ASP.NET.

Extracting data from an XML document without using an XML parser

Here's some lines of the document:
<div class="rowleft">
<h3>Technical Fouls</h3>
<table class="num-left">
<tr class="datahl2b">
<td> </td>
<td>Players</td>
</tr>
<tr>
<td>DAL</td>
<td>
None</td>
</tr>
<tr>
<td>MIA</td>
<td>
Mike Miller</td>
<td>
Mike Miller, Jr.</td>
</tr>
</table>
</div>
I'm interested in extracting the None and Mike Miller and Mike Miller, Jr. from this. I tried using various XML parsers, but 1) the performance is abysmal and 2) the document is apparently not a properly formatted XML document.
One thing I've been thinking about is stripping the document of newlines, splitting it at something like <tr>, seeing which lines contain data (probably using StartsWith()), and extracting it with a regex. That would be efficient enough for my program (doesn't really matter that it takes half a second when downloading the document is five seconds), but I'm interested it alternative solutions.
Relevant
HTML generally isn't properly formatted XML, I suggest you use something like the HTML Agility pack
Trying to parse HTML with string manipulation and regexes is invariably going to be horribly error-prone.
If your document is not well-formed XML, I would recommend using the HTML Agility Pack

How do I read value from code behind on html page? Or any better way of doing that?

Solution: I end up creatting a WCF that accepts a get/post request, then place JQuery within the html page that retrieves the value and hands it off to the web service
I have a html page like below where I will be doing posting to a web site for registrations and my credentials are not suppose to show on the client side.
My question is how/what is the best way of reading the values from code behind or web service or any other way ?
<FORM NAME="web_form" ACTION="https://website.com/registration.php" METHOD="POST">
<TABLE WIDTH=961 BORDER=0 CELLPADDING=2 CELLSPACING=0>
<TR>
<TH WIDTH=380>
<P ALIGN=RIGHT><i>Encrypted Username:</i>
</P>
</TH>
<TD WIDTH=573>
<P><A NAME="username"></A><INPUT TYPE=TEXT NAME="username" VALUE="HOW TO GET VALUE???" SIZE=20 STYLE="width: 1.69in; height: 0.23in"></P>
</TD>
</TR>
<TR>
..............
.................
Switch the input box in to an ASP control?
<asp:TextBox runat="server" ID="username" ClientIDMode="Static" />
Then in your code behind:
this.username.Text
There's probably a little more that we need to know to make a perfect suggestion, but there's tons of different ways that you could do this.
If you have access to the registration page -- which would be ideal -- you could send a base64encoded string via the URL or via hidden input in the form field posted on submit to the reg page and then base64 decode it before passing in. Similarly, you could salt the value with any number of different methods and "un-salt" it at the application.
Merely hiding it in a hidden input field probably won't suffice here as that code is certainly available on a view source, unless the data inside it is sufficiently obfuscated.
There are javascript obfuscators that will do a sufficient job, but they'll be unavailable if the user has javascript turned off. It won't affect 99% of the users out there, but it is something to think about.
Perhaps you could set this up as a dynamic page (not HTML) and set some sort of a constant? Perhaps a session variable that you then call in at the registration page?
You can do it on client side with JavaScript:
INPUT TYPE="text" NAME="username" VALUE="some value" onclick="CopyValue()" />
function CopyValue()
{
var myValue = document.getElementById('username').value;
}
Not an answer but just a suggestion. In HTML always try to keep your values in quotes. Always a good programming practice. Will definitely help you if you are trying to move from HTML to XHTML or XML. Good Luck!

Categories

Resources