0

When someone hits the "email" button on my web page, in jQuery, I put together some plain text and open it with:

document.location.href = "mailto:?subject=" + emailSubject + "&body=" + emailContent;

However, Outlook strips the email of all line breaks.
This issue has been covered extensively on Stack Overflow and elsewhere.

I need to create the email myself, and it will be other people who are reading it. So changing settings in Outlook (to stop it from removing line breaks) doesn't help.

I have tried all the hacks given on the internet to trick Outlook into not removing line breaks.

Among them:

(1) put two spaces before the line (2) three spaces after the line (3) use "\r\n" (4) use two or more "\r\n"s: "\r\n\r\n" or "\r\r\n\n" or (5) add tabs before the newline or after the newline: "\r\n\t" and "\t\r\n."

The tabs are the only characters I can see getting printed, but I need line breaks.

I'm using Outlook Version 1708 (part of Office 365 Pro Plus).

ash
  • 49
  • 1
  • 1
  • 7

1 Answers1

0

Okay, encodeURIComponent works:

document.location.href = "mailto:?subject=" + emailSubject + "&body=" + encodeURIComponent(emailContent);

I did not register the fact that document.location.hrefis a uri so of course it's going to strip out line breaks.

ash
  • 49
  • 1
  • 1
  • 7