Sendgrid传递一个URL到href属性。

问题描述 投票:1回答:1

我试图通过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: '[email protected]',
      from: '[email protected]',
      templateId: 'xxxx',
      dynamic_template_data: {
        subject: 'Testing Templates',

      },
    };


    await sgMail.send(msg);

我如何将URL地址传递给模板,并将其附加到 href 属性中的 <a> 标签?

sendgrid sendgrid-api-v3 sendgrid-templates
1个回答
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..'

      }
...
© www.soinside.com 2019 - 2024. All rights reserved.