Jose Cabrera Zuniga
Jose Cabrera Zuniga

Reputation: 2637

Multi-line email body in JSX

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.

Upvotes: 1

Views: 103

Answers (1)

Sarah Gro&#223;
Sarah Gro&#223;

Reputation: 10879

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`));

Upvotes: 1

Related Questions