Outlook autocleaning my line breaks and screwing up my email format
Asked Answered
P

11

130

I'm sending an email using the dotnet framework. Here is the template that I'm using to create the message:

Date of Hire: %HireDate%
Annual Salary: %AnnualIncome%
Reason for Request: %ReasonForRequest%

Name of Voluntary Employee: %FirstName% %LastName%
Total Coverage Applied For:  %EECoverageAmount%
Guaranteed Coverage Portion: %GICoveragePortion%
Amount Subject to Medical Evident: %GIOverage%

When the messages is received in outlook, outlook tells me "Extra line breaks in this message were removed". And the message displays like this:

Date of Hire: 9/28/2001
Annual Salary: $100,000
Reason for Request: New Hire

Name of Voluntary Employee: Ronald Weasley Total Coverage Applied For:  $500,000 Guaranteed Coverage Portion: $300,000.00 Amount Subject to Medical Evident: $200,000

Note how Outlook incorrectly removes needed line breaks after the name, EECoverageAmount, etc...

It's important for the email recepients to get a correctly formatted email, and I have to assume that some of them use outlook 2003. I also can't assume they will know enough to shutoff the autoclean feature to get the message to format properly.

I have viewed these messages in other mail clients and they display correctly

some more information:

  • I am using UTF-8 BodyEncoding (msg.BodyEncoding = System.Text.Encoding.UTF8)
  • The msg.Body is being read from a UTF-8 encoded text file, and each line is terminated with a crlf.

Question: How do I change the format of the message to avoid this problem?

Pursy answered 29/10, 2008 at 16:48 Comment(4)
While both highly upvoted answers below are right, see this answer for a list of all the rules.Davena
possible duplicate of How do I format a String in an email so Outlook will print the line breaks?Patch
Why does this "feature" even exist?Dare
Try Windows newlines: \r\n. It worked for me.Puncture
K
103

Start every line with 2 spaces and outlook will be "tricked" into keeping your formatting.

So change

Date of Hire: %HireDate%
Annual Salary: %AnnualIncome%
Reason for Request: %ReasonForRequest%

Name of Voluntary Employee: %FirstName% %LastName%
Total Coverage Applied For:  %EECoverageAmount%
Guaranteed Coverage Portion: %GICoveragePortion%
Amount Subject to Medical Evident: %GIOverage%

to

  Date of Hire: %HireDate%
  Annual Salary: %AnnualIncome%
  Reason for Request: %ReasonForRequest%

  Name of Voluntary Employee: %FirstName% %LastName%
  Total Coverage Applied For:  %EECoverageAmount%
  Guaranteed Coverage Portion: %GICoveragePortion%
  Amount Subject to Medical Evident: %GIOverage%
^^ <--- Two extra spaces at the start of every line

Here is the article I found when researching this problem which goes into a little more depth than my answer.

Krenn answered 29/10, 2008 at 18:43 Comment(5)
Here's a handy Regex to sort this out: Regex.Replace(messageBody, @"^(?!\s\s)", " ", RegexOptions.Multiline);Sleepy
Ok, in that regex there are two spaces but this being html it's only displaying one!Sleepy
For code generated plain text emails this is the best solution.Sorensen
Unfortunately it doesn't work -- lines still get mashed together.Punctilio
I also confirmed this does not work with emails opened in Outlook 2021. Is there any working solution?Heilner
A
134

You can also insert a tab character at the end of the line (just before the CR LF). This extra white space will be at the end of the line and hence not visible to user. You might prefer this to having to insert spaces on the left. Note that a single space is not enough (though perhaps multiple spaces would help, I don't know.)

Anschauung answered 12/1, 2009 at 16:58 Comment(5)
Regex.Replace(messageBody, @"(?<!\t)((?<!\r)(?=\n)|(?=\r\n))", "\t", RegexOptions.Multiline)Sleepy
Perfect solution for emails sent from Trac to Outlook users.Spermatozoon
+1 I had to use 3 spaces instead of a tab, but basically this fix worked for me: Regex.Replace(messageBody, @"(?<!\t)((?<!\r)(?=\n)|(?=\r\n))", " ", RegexOptions.Multiline)Pettish
confirmed! Here regex as php snippet: $re = '/(?<!\t)((?<!\r)(?=\n)|(?=\r\n))/m'; $subst = " "; $MailText = preg_replace($re, $subst, $MailText);Kendre
Works for Outlook but breaks text mails on samsungs mail client fpr smartphones :(Kendre
K
103

Start every line with 2 spaces and outlook will be "tricked" into keeping your formatting.

So change

Date of Hire: %HireDate%
Annual Salary: %AnnualIncome%
Reason for Request: %ReasonForRequest%

Name of Voluntary Employee: %FirstName% %LastName%
Total Coverage Applied For:  %EECoverageAmount%
Guaranteed Coverage Portion: %GICoveragePortion%
Amount Subject to Medical Evident: %GIOverage%

to

  Date of Hire: %HireDate%
  Annual Salary: %AnnualIncome%
  Reason for Request: %ReasonForRequest%

  Name of Voluntary Employee: %FirstName% %LastName%
  Total Coverage Applied For:  %EECoverageAmount%
  Guaranteed Coverage Portion: %GICoveragePortion%
  Amount Subject to Medical Evident: %GIOverage%
^^ <--- Two extra spaces at the start of every line

Here is the article I found when researching this problem which goes into a little more depth than my answer.

Krenn answered 29/10, 2008 at 18:43 Comment(5)
Here's a handy Regex to sort this out: Regex.Replace(messageBody, @"^(?!\s\s)", " ", RegexOptions.Multiline);Sleepy
Ok, in that regex there are two spaces but this being html it's only displaying one!Sleepy
For code generated plain text emails this is the best solution.Sorensen
Unfortunately it doesn't work -- lines still get mashed together.Punctilio
I also confirmed this does not work with emails opened in Outlook 2021. Is there any working solution?Heilner
C
26

This answer is on how to "disable" the feature from the Outlook Client.

  • Go to Tools -> "Options ..."
  • In the "Preferences" tab click on "Email Options ..."
  • Uncheck the box "Remove extra line breaks in plain text messages."
  • Hit OK

FYI:I am using Outlook 2007

Cesaria answered 31/8, 2009 at 17:56 Comment(4)
I don't like this feature, either. Among other things, it causes code in emails to be broken and PGP signature checks to fail.Labarum
And in Outlook 2010 it's: File > Options > Mail > Scroll down to the "Message format" section > Untick the "Remove extra line breaks in plain text messages" box.Annalee
This is a client-side solution. Much better would be a reliable method to prevent Outlook to doing this on the server side, i.e. by formatting the mail in a way that doesn't disturb other clients (because you don't know which mail client the receiver will use).Achates
Thanks - and now please guide our 100.000+ newsletter receivers to do thisUnshackle
W
7

Adding "\t\r\n" ( \t for TAB) instead of "\r\n" worked for me on Outlook 2010.

Whisenhunt answered 12/4, 2016 at 15:5 Comment(3)
I "solved" this using "\r\n " (two spaces, no tab) after the newline as a similar hack. Works In Outlook 2016. YMMV.Propagandism
Spaces sucks. The tabulation does rule. Thanks :)Horwitz
This also does not work with emails opened in Outlook 2021. Is there any working solution?Heilner
C
5

I have always had better luck formatting e-mails as html. You may still have the end-user issue of having to set the client to allow html format, but they are usually more familiar with this since so many e-mails do come html formatted. You also have a little more work on your end adding the html tags, but the end result is much more controllable.

@ephemient also suggests: Send as both HTML and plaintext. Good clients will show the latter, Outlook will show the former, everybody is happy (except the programmer who has to do more work).

Contractive answered 29/10, 2008 at 17:32 Comment(2)
Send as both HTML and plaintext. Good clients will show the latter, Outlook will show the former, everybody is happy (except the programmer who has to do more work).Halloran
BTW, s/http/html/g in your answer.Halloran
L
2

Expanding on the Doug L answer, since I think HTML messaging is even more ubiquitous and accepted now than in 2008 when that answer was posted. Here is a little c# snippet to help convert the body and send the message in HTML format:

body = string.Format("<font face='calibri,arial,sans-serif'>{0}<font/>", body.Replace("\r\n", "<br>"));

using (var smtpClient = new SmtpClient() { Host = smtpHost })
using (var msg = new MailMessage(from, emailDistribution, subject, body) { IsBodyHtml = true })
     smtpClient.Send(msg);
Loera answered 17/8, 2017 at 18:2 Comment(0)
C
1

Auto cleaning is an outlook feature which removes extra line breaks. You can prevent it by two ways.

  • First way is to add at least 2 extra spaces before lines while sending the email through code. You can add these extra spaces only before those lines which outlook automatically removes.

  • Second way is to change outlook setting which will prevent outlook from removing extra line breaks.

enter image description here

enter image description here

Crevasse answered 15/3, 2019 at 13:33 Comment(0)
C
0

I'm seeing the same problem when generating a plain-text email and then reading it with Outlook 2003 SP3. It appears you can avoid the removal process by it by keep the line length under 40 characters. May not always be practical.

Carpel answered 12/11, 2008 at 22:0 Comment(0)
Y
0

Put the text in <pre> Tags and outlook will format and display the text correctly.

i defined it in CSS inline in HTML Body like:

CSS:

pre {
 font-family: Verdana, Geneva, sans-serif;
}

i defined the font-family to have to font set.

HTML:

<td width="70%"><pre>Entry Date/Time:       2013-09-19 17:06:25
Entered By:     Chris

worklog mania

____________________________________________________________________________________________________

Entry Date/Time:        2013-09-19 17:05:42
Entered By:     Chris

this is a new Worklog Entry</pre></td>
Yuan answered 24/9, 2013 at 15:43 Comment(1)
I believe the original question refers to plaintext emails, not HTML. You're trying to mix in HTML as the solution.Nonjoinder
A
-1

My text includes '\r\n' but Outlook 2010 does not render line break. Create tokens of lines delimited by '\r\n' and envelope tokens by HTML Paragraph tags. My Email format is HTML. I am generating HTML Body for my email in the code below.

string[] tokens = Regex.Split(objTickt.Description, "\r\n");
  if (tokens.Length > 0)
  {
     foreach (string line in tokens)
     {
         //htmlTW.WriteEncodedText(objTickt.Description.Replace("\r\n", "\n\n"));
         htmlTW.RenderBeginTag(HtmlTextWriterTag.P);
         htmlTW.WriteEncodedText(line);
         htmlTW.RenderEndTag();
     }
  }
Any answered 13/11, 2014 at 8:53 Comment(0)
G
-6

Change your line termination from crlf to either cr or lf.

I suspect that the top of the email uses only cr (or lf), and Outlook expects the rest of the email to follow the same format.

Gratt answered 29/10, 2008 at 17:22 Comment(2)
I tried changing the line terminator to a CR. That didn't work. Then I tried changing it to a LF. That didn't work either.Pursy
Doubtful. Outlook has a highly dubious feature which tries to convert mail with hard line breaks into flowed text. Unsurprisingly, it frequently gets this wrong, as in this case.Bubal

© 2022 - 2024 — McMap. All rights reserved.