22

I am using sendgrid api with nodejs and for some reason the emails are sending but not adding new lines. I've used and also \n but no luck. Any idea what is wrong?

Here is the code I am using

var email = { to: '[email protected]', from: '[email protected]', subject: 'Membership', text: 'Please view in html', html: 'Hello there!,</br>\n\n' + 'Please click on the following link, or paste this into your browser to complete the process:\n\n' + 'Welcome and thanks for joining.\n\n' + '</br>Your details we have are\n\n' + '</br> Name: ' + user + '\n\n' + '</br> Telephone number: ' + number + '</br> email: ' + email + '</br>' }; 
2
  • This is what worked for me: stackoverflow.com/a/60825296/9669133 Commented Oct 10, 2020 at 11:49
  • @ServerSideSkittles why don't you mark the solution as accepted answer? I'm sure there must be at least one solution which worked for you. Isn't it? Commented Jan 12, 2021 at 12:00

4 Answers 4

44

I assume your "Plain Content" setting is turn off in sendgrid account. To allow html tags to work you need to use triple curly braces

{{{TEMPLATE_VARIABLE}}} 

It will parse html tag as html rather than plain text. If you'll use double curly braces

{{TEMPLATE_VARIABLE}} 

it will consider any html tag as plain text only.

Sign up to request clarification or add additional context in comments.

1 Comment

Just remember that after you click the save button in Sendgrid it seems to take up to 5 mins sometimes for the changes to take affect. Was driving me crazy.
26

In places of </br> and \n Use <br>

1 Comment

I was getting this issue in C# with SendGrid. This solution worked for me.
19

So what worked for me was literally all the answers above combined @shikhar bansal + @Vipul Patil + EddieB

  • Use <br> as apposed to a \n

  • In your sendgrid template (if you're using one), use {{{myVariable}}} instead of just two braces {{myVariable}}. This will let sendgrid know, the variable contains html - So that means your <br> will now work.

  • Disable plain text by logging into the Sendgrid account. Then go to your template (again, if you have one). if you don't have one, just follow @EddieB answer. Once you have your template in edit mode you'll see two tabs named "Design" and "Preview". Click on "Preview" then select the "Plain Text" tab. Make sure you "Automatically create plain text version" is turned OFF then you're good to go.

GOOD LUCK & Happy Emailing!

Comments

6

Sendgrid will automatically convert plain/text email to HTML format. Disable this by logging into the Sendgrid account and going to Settings > Mail Settings and turning ON "Plain Content"... Turn on if you don't want to convert your plain text email to HTML

1 Comment

This has now been deprecated by SendGrid due to poor customer take-up of the feature. See Underused Mail Setting Retirement.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.