Search code examples
javascriptoutlookmailtoemail-client

Preserving the formatting of text sent to the mailTo in JS


I am using mailTo to open the outlook client and passing in the mail body.

<a  href="mailto:?body={{infoBoxEmailBtnBody}}&subject={{infoBoxEmailBtnSubject}}" style="text-decoration:none">
   <img src="assets/svg/email-button.svg">
   <label>Email</label>
</a>

However, in case there is any formatting with the body, (i.e. line-break), the same is not getting preserved.

Is there any way this can be achieved. I am using just a text-area (no text-editor) to retrieve the text from the users.


Solution

  • You must url-encode the line breaks:

    mailto:test@example.com?subject=test&body=two%0D%0Alines