自定义策略的SendGrid API发送电子邮件没有主题

发布于 2025-02-01 02:48:49 字数 2619 浏览 6 评论 0原文

我正在使用自定义策略,该策略调用SendGrid API向OTP发送邮件。 API成功发送,但是主题零件不能反映请求的值。

这是我生成JSON的自定义策略代码。

<ClaimsTransformation Id="GenerateEmailRequestBody-Local" TransformationMethod="GenerateJson">
    <InputClaims>
        <InputClaim ClaimTypeReferenceId="email" TransformationClaimType="personalizations.0.to.0.email" />
        <InputClaim ClaimTypeReferenceId="otp" TransformationClaimType="personalizations.0.dynamic_template_data.otp" />
        <InputClaim ClaimTypeReferenceId="email" TransformationClaimType="personalizations.0.dynamic_template_data.email" />
        <InputClaim ClaimTypeReferenceId="subject" TransformationClaimType="subject" />
    </InputClaims>
    <InputParameters>
        <!-- Update the template_id value with the ID of your SendGrid template. -->
        <InputParameter Id="template_id" DataType="string" Value="d-xxxxxxxxxxxxxxxxxxxxxxxxxx" />
        <!-- Todo: update the sender -->
        <InputParameter Id="from.email" DataType="string" Value="[email protected]" />
        <InputParameter Id="from.name" DataType="string" Value="Administrator" />
    </InputParameters>
    <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="emailRequestBody" TransformationClaimType="outputClaim" />
    </OutputClaims>
</ClaimsTransformation>

以下是从自定义策略生成的请求,并发送到SendGrid。

{
    "personalizations": [
        {
            "to": [
                {
                    "email": "[email protected]"
                }
            ],
            "dynamic_template_data": {
                "email": "[email protected]",
                "otp": "086924"
            }
        }
    ],
    "subject": "Verification code",
    "template_id": "d-xxxxxxxxxxxxxxxxxxxxxxxx",
    "from": {
        "email": "[email protected]",
        "name": "Administrator"
    }
}

我错过了一部分吗?请帮忙。

I am using custom policy that calls SendGrid API to send mails for OTP. The API is successful in sending however the subject part does not reflect the value from the request.

enter image description here

This is my custom policy code that generates the JSON.

<ClaimsTransformation Id="GenerateEmailRequestBody-Local" TransformationMethod="GenerateJson">
    <InputClaims>
        <InputClaim ClaimTypeReferenceId="email" TransformationClaimType="personalizations.0.to.0.email" />
        <InputClaim ClaimTypeReferenceId="otp" TransformationClaimType="personalizations.0.dynamic_template_data.otp" />
        <InputClaim ClaimTypeReferenceId="email" TransformationClaimType="personalizations.0.dynamic_template_data.email" />
        <InputClaim ClaimTypeReferenceId="subject" TransformationClaimType="subject" />
    </InputClaims>
    <InputParameters>
        <!-- Update the template_id value with the ID of your SendGrid template. -->
        <InputParameter Id="template_id" DataType="string" Value="d-xxxxxxxxxxxxxxxxxxxxxxxxxx" />
        <!-- Todo: update the sender -->
        <InputParameter Id="from.email" DataType="string" Value="[email protected]" />
        <InputParameter Id="from.name" DataType="string" Value="Administrator" />
    </InputParameters>
    <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="emailRequestBody" TransformationClaimType="outputClaim" />
    </OutputClaims>
</ClaimsTransformation>

Below is request generated from the custom policy and sent to SendGrid.

{
    "personalizations": [
        {
            "to": [
                {
                    "email": "[email protected]"
                }
            ],
            "dynamic_template_data": {
                "email": "[email protected]",
                "otp": "086924"
            }
        }
    ],
    "subject": "Verification code",
    "template_id": "d-xxxxxxxxxxxxxxxxxxxxxxxx",
    "from": {
        "email": "[email protected]",
        "name": "Administrator"
    }
}

Is there a part that I've missed? Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨落画卷 2025-02-08 02:48:49

尝试

  1. 更新主题的转换行为。
<InputClaim ClaimTypeReferenceId="subject" TransformationClaimType="personalizations.0.dynamic_template_data.subject" />
  1. 验证主题索赔具有有效值。尝试将默认值设置为InputClaim。

  2. 更新发送网格门户中的主题字段。

Few things to try

  1. Update the TransformationClaimType for subject.
<InputClaim ClaimTypeReferenceId="subject" TransformationClaimType="personalizations.0.dynamic_template_data.subject" />
  1. Verify subject claim has a valid value. Try setting default value to inputclaim.

  2. Update the subject field in send grid portal.

SendGrid Template Settings

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文