sendgrid / sendgrid-ruby

The Official Twilio SendGrid Led, Community Driven Ruby API Library
https://sendgrid.com
MIT License
620 stars 324 forks source link

How to substitute \n or carriage returns #460

Closed netwire88 closed 3 years ago

netwire88 commented 3 years ago

Hi, We have a string that contains \n. How do we submit it to the mail send API as a variable for dynamic template?

I tried:

        content.gsub!("\n", "<br/>")
        personalization.add_dynamic_template_data(
          {
            'subject' => subject,
            'content' => content
          }
        )

but the text shows up as <br/> and not escaped.

I chatted with SendGrid support and they referred me to post here.

netwire88 commented 3 years ago

I couldn't find an answer here but found it on Stackoverflow. Essentially, I need to

  1. replace \n with <br>
  2. Use {{{content}}} instead of {{content}} in the dynamic template