0

ts

 send(): void {
    const body: string = `First Name: ${this.form.value.firstName}` + '\n' + `Last Name:${this.form.value.lastName}`;
    console.log('body', body);
    const url: string = `mailto:me@y.com?Subject=Sell My House&body=${body}`;
    window.open(url);
  }

Console.log shows correctly:

body First Name: sampath
Last Name:lokuge

But why email client doesn't show it correctly

enter image description here

cjd82187
  • 3,468
  • 3
  • 15
  • 19
Sampath
  • 63,341
  • 64
  • 307
  • 441
  • Try \n\r instead of just \n. Explanation is [here](https://social.msdn.microsoft.com/Forums/en-US/47af2197-26b4-4b9e-90e8-bfa9d5cd05b4/what-is-the-deference-between-r-n-and-rn-) – barinbritva Jul 21 '20 at 13:34
  • 1
    @barinbritva No difference. Same result. :( – Sampath Jul 21 '20 at 13:40
  • Another thing may be here. Possible it's important to specify content type header for Windows Mail client. But, it's just my guess – barinbritva Jul 21 '20 at 13:43
  • Does this answer your question? [Insert a line break in mailto body](https://stackoverflow.com/questions/22765834/insert-a-line-break-in-mailto-body) – cjd82187 Jul 21 '20 at 14:24

1 Answers1

2

OP's feedback

I have done it like so: i.e. %0D%0A

const body: string = `First Name: ${this.form.value.firstName}` + '%0D%0A' + `Last Name: ${this.form.value.lastName}`

Original

That is normal behavior for HTML and whitespace. All whitespace is condensed into one, and considered a single space.
https://developer.mozilla.org/en-US/docs/Glossary/Whitespace

The css white-space property can fix that white-space: pre-line is likely what you want, but there are other options https://developer.mozilla.org/en-US/docs/Web/CSS/white-space

Now, weather or not your email clients will respect that css white-space property you'll need to test. Otherwise you may want to add HTML line breaks <br> or wrap each line in a <div> or <p>

Sampath
  • 63,341
  • 64
  • 307
  • 441
cjd82187
  • 3,468
  • 3
  • 15
  • 19
  • No. I need to do this is using `Typescript/Javascript`. i..e No `CSS` – Sampath Jul 21 '20 at 14:19
  • Just realized you are creating a mailto link and clicking that for the user, so this isn't quite answering the question. – cjd82187 Jul 21 '20 at 14:21
  • You can see that I need to add lot of Typescript things on that page. – Sampath Jul 21 '20 at 14:22
  • I've commented on your original question again, your problem is specific to using `mailto` links to open an email, not really html emails themselves. – cjd82187 Jul 21 '20 at 14:25