C# Email - New lines not rendering with white-space: pre-wrap - c#

I have an email with a table and one value contains a string with multiple lines. (enter-key) When viewed in outlook or view source in IE, the white-space is not working.
Any idea or any solution?
Thanks.

This is related to Outlook (not C#). I have the same problem (using Java to send mail). I am using CSS style white-space:pre-wrap; on a span and it works well to preserve tabs, spaces, new lines and wrap text in GMail - web, Android and iOS.
As per my experimentation on Outlook 2016 Windows app and webapp (outlook.office365.com):
Value pre-wrap does not preserve new lines in both Windows app and webapp
Value pre preserves new lines in Windows app, but does not do so in webapp

New lines within html are not rendered as such. You need to add <br> tags at the end of each line to make sure that the email is rendered correctly with the new lines.
You can do this within your c# code by replacing every new line character in your problematic value with <br>.

Related

Windows Phone Webbrowser - Cannot input text on empty line in contenteditable div

I'm developing a note app in Windows Phone 8.1 and here is a bug I cannot fix.
Say you have an WebBrowser control and loaded a html page, inside which is a content-editable div.
<div id="content" contenteditable="true">
<div>Please edit content here...</div>
</div>
After running this app, I can edit content inside div.
The strange thing is, If I tap return several times, there will be several empty lines. Then I tap empty line before current caret position, and try to input text there. It turns out I cannot input text there, and text will always append to last line of the entire div.
content here...
(Wish to insert text here.)
But text goes here.
I tested it on my lumia 925 device running Windows Phone 8.1 and using Chinse Input Method.

Unable to insert a tab spacing with \t

I'm trying to do a password recovery with SMTP. In the email, i've added some necessary text and hyperlink for the user to recover their password. As you can see the code here, i've added a hyper link.
strBody.Append("Click here to change your password.");
In order to add a non-hyperlink text, i added this statement behind the code.
strBody.Append("Click here to change your password. \t\t\t\t This is a computer generated email for your password recovery. \t\t please do not reply this email.");
I've added a \t in the string but instead it doesn't show any tab spacing in the email. What have i done wrong here?
The fact that you have HTML in your body makes me assume that you are sending HTML emails. If this is the case then your tabs will be in the source but HTML collapses all whitespace which includes tabs.
You'll have to either use proper HTML to indent your text (eg margins on block elements) or use plain text where tabs and such like will work.
There are no tabs in HTML. That \t is a Windows character code. You'll need to either throw a <span style="margin-left: 1em;"> around the text or use (many times).
I think the right approach is this:
<span style=\"margin-left: 1em;\">This is a computer generated email for your password recovery.</span>
use multiple times instead of tabs in your html message body.
You're probably sending the email as HTML, therefore the tab (\t) will be rendered as a single space, which is normal.
Either change the email format normal (plain text) or add styling to mimic the indentation you want.
Tab characters inside <pre></pre> tags seem to survive.
I have not tried this in an e-mail yet, but you can give it a shot.
<pre>
a b c d
</pre>

Append Meta Tag in Html - Win Phone 8 - C#

Im building a Windows Phone 8 App which has a webbrowser. I would like append a meta tag inside the head tag on the page which is shown in my webbrowser.
I've tried it with this but it gives me a System Exception Error 80020101.
WebBrowser.InvokeScript("eval", #"document.getElementsByTagName(""head"")[0].appendChild(""<meta
name=""viewport"" content=""user-scalable=no"">"")");
I was told to try it with this code below but I dont think you can use that in C#.
link=document.createElement('link');
link.href='href';
link.rel='rel';
document.getElementsByTagName('head')[0].appendChild(link);
First of all make sure this property is set on your webBrowser object:
webBrowser.IsScriptEnabled = true;
Then you should also probably check your javascript method in the desktop IE11 debugger, whether the code actually works as expected. Adding new meta tags into your page might not be that easy.

Checkbox in an email

I am creating an email using the c# MailMessage and I am trying to add a checkbox that doesn't need to be clicked. The checkboxes will be used for a checklist of what to bring to an event (like a packing list). I have:
MailMessage objEmail = new MailMessage();
objEmail.From = new MailAddress("sender#hotmail.com");
objEmail.To.Add(new MailAddress("example1#hotmail.com"));
objEmail.CC.Add(new MailAddress("example2#hotmail.com"));
objEmail.Bcc.Add(new MailAddress("example3#hotmail.com"));
objEmail.Subject = "Packing list!";
objEmail.IsBodyHtml = true;
objEmail.Body = #"<div width=""800px"">
<h3>WHAT TO BRING</h3>
<form>
<input type=""checkbox"" name=""item"" value=""shirt"">Shirt<br>
<input type=""checkbox"" name=""item"" value=""shoes"">Shoes
</form></div>";
but when I send the email the checkboxes do not appear in the list.
Output in outlook using outlook.com:
WHAT TO BRING
I have a bike
I have a car
Output in outlook using Microsoft Outlook:
WHAT TO BRING
[ ]I have a bike
[ ]I have a car
Output in outlook using hotmail.com:
WHAT TO BRING
I have a bike
[]I have a car
So the problem is with the mail client but it is inconsistent what the problem is. I s there any way to make a consistent output?
Is there a way with html that works to create the checkboxes or do I just need to include images of a checkbox?
Thanks in advance.
My guess is that their in inconsistency with the way the email clients handle check boxes.
Why not change each to [X] which is plain text so all email clients can see it.
Outlook.com has an issue to display multiple check or radio buttons within a single parent. / / / etc
add a table in there and add the 2 check boxes in a separate row and it should work fine.
weird Microsoft thinking
All email clients have their own rules on what's allowed. You may find that most providers don't allow JavaScript and just some allow positioning elements while some don't.
Your best bet is to use a plain text form or maybe an image of what the form looks like. And when I say image, don't mean make the entire thing an image, have images for each checkbox. Once you click anywhere in this form it opens up on your site to interact with it.
Furthermore, you really shouldn't be building html in your code like you are. Put that in an MVC view or a webforms partial and invoke the file from code. Using this approach you can still inject dynamic data into the template while putting the HTML where it belongs.

Sending SMS text with line break/new line

I am developing SMS portal in asp.net c# where people register & send sms.
I M Using multiline asp:textbox for input message. i want to break line where user hit enter/new line in textbox. help me if there any textboxeditor which support only <br/> or any other solutions.
from my own experience the default asp:textbox control with TextBoxMode=MultiLine; which automatically adds \r\n for line breaks will do the trick and no additional edit is needed
and html tags like </br> is not processed .
Use textarea tag and escape text on the server side. Replace each line break with </br>, but other tags show as plain text or add some validation.

Categories