从锚标签中删除Sendgrid动态模板HREF [英] Sendgrid Dynamic Template Stripping HREF from Anchor tags

查看:158
本文介绍了从锚标签中删除Sendgrid动态模板HREF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态电子邮件模板,用于向用户发送一个唯一的令牌链接以重置其密码.我将链接分配给请求对象中个性化设置的dynamic_template_data部分中名为"link"的字段.收到电子邮件后,我的定位标记没有href属性.

I have a dynamic email template for sending a user a unique token link to reset their password. I assign the link to a field named 'link' in the dynamic_template_data section of my personalizations in my request object. When I receive the email, my anchor tag has no href attribute.

这是我的请求对象:

{
        method: "POST",
        url: "/v3/mail/send",
        headers: {
          "content-type": "application/json"
        },
        body: {
          personalizations: [
            {
              to: [{ email: email, name: name }],
              dynamic_template_data: {
                link: link
              }
            }
          ],
          // some other content
          // ...
          template_id: Constants.EMAIL.RESET_PASSWORD
        },
        json: true
      }

还有我的sendgrid动态模板中的html:

And the html in my sendgrid dynamic template:

<div>Use the following link to reset your password: <a href="{{link}}">{{link}}</a></div>

当我收到电子邮件时,链接的文本已正确填写了我的动态内容,但是该元素没有href属性,因此它呈现为纯文本且不可点击:

When I receive the email, the text of the link is correctly filled in with my dynamic content but the element has no href attribute so it renders as plain text and isn't clickable:

尤其奇怪的是,当我在SendGrid的设计编辑器上预览动态模板时,href字段正确地填充了我传入的测试数据.

What's particularly weird is that when I preview my dynamic template on SendGrid's design editor, the href field correctly populates with the test data I pass in.

推荐答案

在获得SendGrid支持后,我设法找到了问题.

After some back-and-forth with SendGrid support, I managed to find the issue.

因为我一直在本地环境中开发此功能,所以我包含在请求正文中的链接指向我的本地主机.我的链接变量的定义如下:

Because I've been developing this feature in my local environment, the link that I include in my request body points to my localhost. My link variable was being defined as follows:

  link = "localhost:8080/#/resetPassword/" + token;

作为测试,我将链接更改为以下内容,并且可以正常工作:

As a test, I changed the link to the following and it worked:

link = "https://google.com"

这使我怀疑缺少HTTP协议是导致此问题的原因.将其更改为以下内容可解决此问题:

This made me suspicious that the lack of an http protocol was causing the issue. Changing it to the following fixed the issue:

  link = "http://localhost:8080/#/resetPassword/" + token;

我假设这是锚标记元素本身的一个怪癖,尽管我不太了解该机制,所以如果有人可以为我详细说明这一点,我将不胜感激.

I'm assuming this is a quirk of the anchor tag element itself, though I don't quite understand the mechanism so if someone could elaborate on that for me I'd appreciate it.

这篇关于从锚标签中删除Sendgrid动态模板HREF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆