Multi-line email body in JSX

Asked by At

I am trying to create an email with a multi line body using:

<a href={"mailto:" + this.state.emailsToNotify + 
         "?subject=" + this.state.mname 
         + "&body=Please, review: " + "\n" + this.state.mname + "\n" + "at " + emailBody 

        }>
    <button style={button4TableStyleObject('#007a86', '#ebf5ff', '#ff3900 #ff3900')} >{'Notify Selected'} </button>
</a>

However Outlook opens this email using a single line. Is there a way to make it multi-line? I used "\n" with double quotes but no luck.

1 Answers

1
Connum On Best Solutions

You have to encode the parameters you pass in a mailto: url. For a line break, you can use %0A:

<a href="mailto:[email protected]?body=First%20line%0Asecond%20line%0A%0ANew%20paragraph">your message here</a>

In order to not have to do this manually, you can use encodeURIComponent():

console.log(encodeURIComponent(`first line
second line

paragraph`));