How to Format a String in an Email So Outlook Will Print the Line Breaks

How do I format a String in an email so Outlook will print the line breaks?

You need to use \r\n as a solution.

Outlook autocleaning my line breaks and screwing up my email format

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.

javascript email linebreaks

try to force newline with %0D%0A sequence in the body_message variable

edit: see How to break line in JavaScript?

How to add line breaks through java and outlook should accept line breaks

\CarriageReturn\LineFeed aka \r\n

Newlines in Outlook 365 e-mail sent from Play Java

If your data is HTML, line break is the <br> HTML element.

Send a text/plain email and prevent Outlook from collapsing lines

I finally found this question and answer, and my solution is:
Prepend each newline with a tab character which might be "optimized away" by Outlook, e.g. because it is not followed by another newline.

If it can be done without too much effort, of course it would help to generate a mail which contains both text/plain and text/html; but if done solely for this reason, it looks like overkill.

HTML-only mails would work as well, but they are less trustworthy than plain-text mails (because people can be tricked into activating other URLs than the one in the link text), so e.g. SpamAssassin doesn't like them.

Here is a Python function which inserts a tab before every single line break (but not before sequences of two or more):

def harden_linebreaks(s):
tmp = []
prev = None
for line in s.splitlines():
tmp.append((prev, line))
prev = line
tmp.append((prev, None))
res = []
for tup in tmp:
line, next = tup
if (line and next
and not line.endswith('\t')):
line += '\t'
res.append(line)
return '\n'.join(res[1:])

Insert a line break in mailto body

I would suggest you try the html tag <br>, in case your marketing application will recognize it.

I use %0D%0A. This should work as long as the email is HTML formatted.

<a href="mailto:email@mycompany.com?subject=Subscribe&body=Lastame%20%3A%0D%0AFirstname%20%3A"><img alt="Subscribe" class="center" height="50" src="subscribe.png" style="width: 137px; height: 50px; color: #4da6f7; font-size: 20px; display: block;" width="137"></a>

You will likely want to take out the %20 before Firstname, otherwise you will have a space as the first character on the next line.

A note, when I tested this with your code, it worked (along with some extra spacing). Are you using a mail client that doesn't allow HTML formatting?

Outlook removes line breaks UTF-8 and Plain Text mails, regardless of the configuration

Finally found the solution, leaving it here:

  1. Non-english Windows 10:
  • Windows Settings App (New Version)
  • Date & Region
  • Language
  • Administrative Language Options
  • Language for Unicode incompatible Apps: Change Regional Scheme Button
  • Make sure the Country matches.
  • Disable "Beta: Unicode UTF-8 support for worldwide languages"
    Thats requirement #1.

Full reboot is now needed and cannot be avoided.


  1. Outlook 365:
  • File
  • Settings
  • Advanced
  • [x] Automatic encoding for Outgoing e-mails
  • Prefered encoding for Outgoing e-mails: Unicode (UTF-8)
    Thats requirement #2
  • Same for vCards.

It seems plaintext messages in de_DE win-10, de_DE outlook 365 + exchange server only work reliable in this combination.

Otherwise any \r\n is removed by Outlook, regardless of the "Remove unneccessary whitespace" setting.

New lines (\r\n) are not working in email body

You need to use a <br> because your Content-Type is text/html.

It works without the Content-Type header because then your e-mail will be interpreted as plain text. If you really want to use \n you should use Content-Type: text/plain but then you'll lose any markup.

Also check out similar question here.



Related Topics



Leave a reply



Submit