I sent an html via outlook.
In the html, I aligned a word to the right, but in the received e-mail, the word is mixed - the first letter has become the last letter.
This only occurs when the first letter is a number.
I sent the following html:
<div dir="rtl" style="margin: 20px auto; width: 650px; text-align: center; font-family: Tahoma;">
<table dir="rtl" style="width: 650px; margin: 0 auto; text-align: right; font-family: Tahoma; font-size: 0; font-weight: normal; color: #000;" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="background-color: #d0f2f6; padding: 15px 20px; margin: 0; color: #135861; font-size: 13px; font-weight: 400;">
שלום
<br /><br />
המספר הוא:<br />
<b dir="rtl" style="font-family:consolas">1fD9xG8j</b>
<br /><br />
</td>
</tr>
</tbody>
</table>
</div>
But I got the following mail:
Why does outlook change the word '1fD9xG8j' to 'fD9xG8j1' ?
This is the code in c# which sent the mail:
var smtp = new SmtpClient(SmtpServer);
var message = new MailMessage();
message.Subject = subject.Trim();
message.Body = body.Trim();
message.IsBodyHtml = true;
message.BodyEncoding = Encoding.UTF8;
smtp.Send(message);
Remove dir="rtl" from Table tag and try.
I saw, that many times, Outlook text editor adds code to the source code. This happens because Outlook is generating the email source code using mostly VML (Vector Markup Language) which causes changes in the code. There are add-ins to import a clean HTML source code, to an Outlook email, in order to get it displayed correctly.
I tried to get around the problem with the following code:
<div dir="ltr" style="font-family:consolas;font-weight:bold;text-align:right">1fD9xG8j</div>
I changed dir="ltr", and added style text-align:right,
and it works!
Related
This question already has answers here:
How do I remove all HTML tags from a string without knowing which tags are in it?
(5 answers)
Closed 2 years ago.
I am getting this Html string from system
<h1>PDF Attachment</h1>
<h1 style="color: rgb(51, 51, 51); text-align: center;">
<p style="font-size: 14px; font-weight: 400; text-align: justify;">Your service detail are following</p><p style="font-size: 14px; font-weight: 400; text-align: justify;">
<table>
<tr><td></td></tr>
</table>
<br>
</p>
<p style="font-size: 14px; font-weight: 400; text-align: justify;">
<br>
</p>
</h1>
I have two h1 tags in this string. I want to remove "h1" tag in which "table" tag is used.
How can i remove it programmatically?
You can use HtmlAgilityPack:
var content = #"<h1>PDF Attachment</h1><h1 style=""color: rgb(51, 51, 51); text-align: center;""><p style=""font-size: 14px; font-weight: 400; text-align: justify;"">Your service detail are following</p><p style=""font-size: 14px; font-weight: 400; text-align: justify;""><table><tr><td></td></tr></table> <br></p><p style=""font-size: 14px; font-weight: 400; text-align: justify;""><br></p></h1>";
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(content);
var h1NeedsToRemove = htmlDoc.DocumentNode.SelectNodes("/h1").Where(i => i.ChildNodes.Any(c => c.Name == "table")).FirstOrDefault();
var childNodesOfH1 = h1NeedsToRemove.ChildNodes;
h1NeedsToRemove.Remove();
htmlDoc.DocumentNode.AppendChildren(childNodesOfH1);
It will give you desired output:
<h1>PDF Attachment</h1>
<p style="font-size: 14px; font-weight: 400; text-align: justify;">Your service detail are following</p><p style="font-size: 14px; font-weight: 400; text-align: justify;">
<table>
<tr><td></td></tr>
</table>
<br>
</p>
<p style="font-size: 14px; font-weight: 400; text-align: justify;">
<br>
</p>
I have extracted some text from an html document. Now i need to extract the html tags of this text too. How can i do this
Example:
Input text :
<td><div style="TEXT-INDENT: 0pt; DISPLAY: block; MARGIN-LEFT: 0pt; MARGIN-RIGHT: 0pt" align="left"><font style="DISPLAY: inline; FONT-FAMILY: arial, sans-serif; COLOR: #2995d2; FONT-SIZE: 36pt; FONT-WEIGHT: bold">New Jobs</font></div></td> <td valign={0}top{0} width={0}40%{0} style={0}TEXT-ALIGN: right{0}></td>
Extracted Text:
New Jobs</font></div></td> <td valign={0}top{0} width={0}40%{0} style={0}TEXT-ALIGN: right{0}></td>
Now i need the starting tags of this text too. How to get them ?
I'm generating a PDF file based on some HTML, using the pechkin dll.
This is all working nicely except the I need to it add a page break at certain places and I don't know how.
I thought that using a css page-break-before, but that doesn't seem to work.
An example of the HTML I'm using is:
<table style="border-top: 0px solid black; border-bottom: 2px solid black; height: 30px; width: 800px;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width: 200px;"><strong>Recommendation</strong></td>
<td style="width: 600px;">[6060:Builder Recommendation]</td>
</tr>
</tbody>
</table>
<table style="page-break-before: always;border-top: 0px solid black; border-bottom: 2px solid black; background-color: #99ccff; height: 30px; width: 800px;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>Summary of Actions</strong></td>
</tr>
</tbody>
</table>
The code I'm using to generate the PDF is as below:
Dim buf As Byte() = Pechkin.Factory.Create(New GlobalConfig().SetMargins(New Margins(20, 20, 20, 20))
.SetDocumentTitle("").SetCopyCount(1).SetImageQuality(100)
.SetLosslessCompression(True)
.SetMaxImageDpi(300)
.SetOutlineGeneration(True)
.SetOutputDpi(1200)
.SetPaperOrientation(True)
.SetPaperSize(PaperKind.A4)
.SetImageQuality(100)
.SetPaperOrientation(False))
.Convert(New ObjectConfig()
.SetPrintBackground(True)
.SetAllowLocalContent(True), strHTML)
Return buf
Any ideas?
Add a div before your table.
<div style='page-break-after:always'></div>
I have a HttpWebRequest from which the remote URL which returns an XML as reponse. Now, i want to parse this XML and read the content and show in to a DIV as HTML content.
Web Request:
protected string GetWebSiteContents(string url)
{
// Create HttpWebRequest
HttpWebRequest httpWebReq = (HttpWebRequest)WebRequest.Create(url);
httpWebReq.UserAgent = ".NET Framework Client";
HttpWebResponse httpWebRes = (HttpWebResponse)httpWebReq.GetResponse();
StreamReader sr = new StreamReader(httpWebRes.GetResponseStream());
// Read the stream a line at a time and place each one into the stringbuilder
System.Text.StringBuilder sb = new System.Text.StringBuilder();
string strLine;
while ((strLine = sr.ReadLine()) != null)
{
// Ignore blank lines
if (strLine.Length > 0)
sb.Append(strLine);
}
sr.Close();
httpWebRes.Close();
return sb.ToString();
}
enter code here
Show into Div:
result.InnerHtml = GetWebSiteContents(url);
From above code i am getting the XML Response from URL sent. Now, i want to show Parse this XML and show data into a DIV say div with id=result with runat=server.
Reuturned XML Response:
<?xml version="1.0" encoding="UTF-8"?><document><cert_link>http://certacell.com/embed/cert.html?certid=SEZQ-5701-X98H-72</cert_link><cert_id>SEZQ-5701-X98H-72</cert_id>**<cert_data>**<div id="certacell_cert"><link
href="http://www.certacell.com/static/css/certificate.bootstrap.css" rel="stylesheet" /><link href="http://www.certacell.com/static/css/certificate.new.css" rel="stylesheet" />
<style> hr { -moz-border-bottom-colors: none; -moz-border-left-colors: none; -moz-border-right-colors: none; -moz-border-top-colors: none; border-color: gray; border-image: none; border-right: 0 none; border-style: solid none none;
border-width: 1px 0 0; margin-bottom: 20px; margin-top: 20px;} a { color: #4067f9; text-decoration: none;} </style> <div class="container header col-lg-12" ><img style="margin-top: 1%;"
class="col-lg-3" src="http://www.certacell.com/static/images/cert/logo.png"><h1 style="margin-top: 2%; color: #ffffff; text-shadow: black 0.2em 0.2em 0.3em;" class="" > | Device History
Report</h1></div> <div class="separator container" ></div><div class="content container" style="padding-top: 1%;"><div class="col-lg-6 text-center"
style="padding-top: 4%;"><h4 class=""> Certification Created on: 12 Sep 2013 04:01pm </h4><h4 class=""> Unique Certification ID:</h4><h2 class=""> SEZQ-5701-
X98H-72</h2><div class=""></div> <div class="text-left col-lg-offset-2 clearfix"><hr class="col-lg-9" > <div class="clearfix"></div><span
style="margin-top: 10%; font-size: x-large"> Device Carrier: AT&T Wireless </span> <br class="clearfix"><span style="margin-top: 10%; font-size: x-large"> Device Manufacturer: NA
</span> <br class="clearfix"><span style="margin-top: 10%; font-size: x-large"> Device History: Clean </span></div></div> <div class="col-lg-6"> <br
class="clearfix"><div class="col-lg-offset-1"><div class="row"><img src="http://www.certacell.com/static/images/cert/check.png" class="col pull-left"> <span
style="font-size: large; padding-left: 4%; " class="col-lg-9"> This device is Clear for Activation on AT&T Wireless</span></div> <br class="clearfix"><div
class="row"><img src="http://www.certacell.com/static/images/cert/check.png" class="col pull-left"> <span style="font-size: large; padding-left: 4%;" class="col-lg-9"> This
device is Certified to be an Authentic NA Device</span></div> <br class="clearfix"><div class="row"><img src="http://www.certacell.com/static/images/cert/check.png"
class="col pull-left"> <span style="font-size: large; padding-left: 4%; padding-top: 10px;" class="col-lg-9"> This device has NOT been reported lost or stolen </span></div></div>
<br class="clearfix"><div style="color: gray; font-size: larger">To verify this ceriticate’s authenticity please visit <a href="http://www.certacell.com"
target="_blank">www.CertaCell.com</a>.<br class="clearfix"> Certificate is subject to Certacell <a href="http://www.certacell.com" target="_blank">terms and
conditions.</a></div></div></div><div class="separator container" ></div></div>**</cert_data>**<clean>True</clean></document>
Is it possible to return the data of '**cert_data tag ' and show as html to a DIV ?**
Help appreciated!
how can get innerhtml of a server side element with c# (with another server-side controls inside)?
or what is the best way for designing email body with visual studio 2010?
i have some codes in c# for sending emails ...(supporting html body)
so i am looking for a way for scape of hardcoding html body!
and so made a server side div in design mode:
<div runat="server" id="MainDiv" style="direction: rtl; font: 12px tahoma,arial,sans-serif; width: 700px;
background-color: #f5f5ff; border: 2px solid #003366;">
<div id="Header" style="width: 690px; background-color: #637eb0; height: 40px; margin: 5px auto;
position: relative;">
<img src="Images/logo.png" alt="logo" title="soscharge" style="width: 200px; position: absolute;
top: 4px; left: 10px;" />
<span style="color: #69fbfd; font: bold 13px tahoma,arial,sans-serif; position: absolute;
top: 11px; right: 10px;">hi ...</span>
</div>
<div id="Content" style="padding: 10px 10px;">
<ul style="margin:0px;padding:0px 10px 10px 10px;">
<li>
title1 : ---
</li>
<li>
title 2 :
<asp:Label ID="lblOredr_Id" runat="server" Text="---" ForeColor="Red"></asp:Label>
</li>
</ul>
<br />
<p style="text-align: center;color:#fd00dc;">
bla bla</p>
</div>
</div>
but i can n't get innterHtml of this div for my email body by below code :
string s = MainDiv.InnerHtml.ToString();
ERROR :
Cannot get inner content of MainDiv because the contents are not
literal.
also i have a server side table inside MainDiv And i want to add some data dynamically to this table.
with this situation what can i do for getting html for email body ?
thanks in advance
You can't invoke InnerHtml on a div unless its contents are literal (i.e. there aren't server controls contained inside it). But you can force it to render to a string by doing something like this:
var sb = new StringBuilder();
mainDiv.RenderControl(new HtmlTextWriter(new StringWriter(sb)));
string s = sb.ToString();