【问题标题】:Sendgrid pass an URL to href attributeSendgrid 将 URL 传递给 href 属性
【发布时间】:2020-01-19 23:39:12
【问题描述】:

我正在尝试通过 sendgrid 电子邮件发送重置密码链接。我的邮件模板是这样的

<html><head>
      <title>Reset Password</title>
      </style>
      <!--user entered Head Start--><link href="https://fonts.googleapis.com/css?family=Fira+Sans+Condensed&display=swap" rel="stylesheet"><style>
    body {font-family: 'Fira Sans Condensed', sans-serif;}
</style>
    </head>
    <body style="background-color:#9E9E9E;">
      <div style="padding:20px;border:1px solid #9E9E9E;background-color:white">
      <h1>Reset Password</h1>
      <hr>
      
      <p>Click the button below to reset your password.</p>
      <a href="" style="display:inline-block;padding:10px;background-color:#2196f3;color:white">RESET PASSWORD</a>
      <p>If you did not make this
      request, please ignore this email.</p>
      </div>
      <div>
      <p style="padding:20px;border:1px solid #9E9E9E;">Send by Information Systems.</p>
      <div>
    
  
</body></html>

而后端代码是这样的

const msg = {
      to: 'someone@gmail.com',
      from: 'sender@example.org',
      templateId: 'xxxx',
      dynamic_template_data: {
        subject: 'Testing Templates',

      },
    };


    await sgMail.send(msg);

如何将 URL 地址传递给模板并将其附加到 &lt;a&gt; 标记中的 href 属性?

【问题讨论】:

    标签: sendgrid sendgrid-api-v3 sendgrid-templates


    【解决方案1】:

    我认为你很接近。做下面这样的事情应该可以工作

    <a href="{{url}}" style="display:inline-block;padding:10px;background-color:#2196f3;color:white">RESET PASSWORD</a>
    
    

    然后在你的dynamic_template_data

    ...
     dynamic_template_data: {
            subject: 'Testing Templates',
            url: 'https://somelink.com..'
    
          }
    ...
    

    【讨论】:

      猜你喜欢
      • 2017-11-23
      • 1970-01-01
      • 2016-06-16
      • 1970-01-01
      • 2017-06-05
      • 1970-01-01
      • 2021-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多