Sendgrid not sending text to new line

馋奶兔 提交于 2021-01-27 02:22:12

问题


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>'
      };

回答1:


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.




回答2:


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




回答3:


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




回答4:


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!



来源:https://stackoverflow.com/questions/33573600/sendgrid-not-sending-text-to-new-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!