简体   繁体   中英

Can I add script tags to sendGrid templates?

I am trying to add the following script to a sendgrid template

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "EmailMessage",
  "potentialAction": {
    "@type": "ViewAction",
    "target": "https://watch-movies.com/watch?movieId=abc123",
    "name": "Watch movie"
  },
  "description": "Watch the 'Avengers' movie online"
}
</script>

On saving the sendgrid template, it shows saved successfully, but on actually it is not getting saved on refresh. I am guessing sendgrid does not allow to add scripts to email. My purpose is to add gmail actions ( see https://developers.google.com/gmail/markup/reference/go-to-action )

Edit: Read the Google gmail documentation again. My guess is that Sendgrid may be removing script tags for security reasons, so you can use div tags instead, in combination with my advice below.

<div itemscope itemtype="http://schema.org/EmailMessage">
  <div itemprop="potentialAction" itemscope itemtype="http://schema.org/ViewAction">
    <link itemprop="target" href="https://watch-movies.com/watch?movieId=abc123"/>
    <meta itemprop="name" content="Watch movie"/>
  </div>
  <meta itemprop="description" content="Watch the 'Avengers' movie online"/>
</div>

I'm currently facing a similar challenge on adding call-to-actions for gmail via sendgrid.

I think there are 3 different options:

First, if you want to add custom html you may need to import it as a module . Here are some examples .

Here are two other potential solutions:

  1. Create a new template using The Code Editor
  2. Import the previous template you created using The Design Editor
  3. Add the schema script snippet to your template in The Code Editor

You can also try editing the HTML head .

The most email client does not support javascript due to security concerns. Any good mail client will not support executable code within an email. Most email clients remove or disable JavaScript in order to prevent malicious code execution or other security issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM