17

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: 'test@gmail.com',
      from: 'hello@test.com',
      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>'
      };
ServerSideSkittles
  • 2,713
  • 10
  • 34
  • 60

4 Answers4

36

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.

Vipul Patil
  • 1,250
  • 15
  • 27
  • 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. – MadMac Jun 27 '23 at 04:02
23

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

shikhar bansal
  • 1,629
  • 2
  • 21
  • 43
13

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!

PhillipJacobs
  • 2,337
  • 1
  • 16
  • 32
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

EddieB
  • 4,991
  • 3
  • 23
  • 18
  • This has now been deprecated by SendGrid due to poor customer take-up of the feature. See [Underused Mail Setting Retirement](https://sendgrid.com/docs/ui/account-and-settings/retired-mail-settings/). – user692942 Jan 10 '21 at 16:15