【问题标题】:Mailchimp not rendering variablesMailchimp 不呈现变量
【发布时间】:2021-09-17 17:56:03
【问题描述】:

我正在使用 Mailchimp 模板通过 Mandrill 发送电子邮件。电子邮件发送成功。但是变量没有渲染。我尝试了很多设置,但不幸的是,它不起作用。我的代码如下所示。

<p>Dear {{customerName}},</p>

<p>Thank you for using XXXXX to process your return.</p>

<p>All you have to do is bring your parcel along with&nbsp;this e-mail to {{pudoLocation}} at {{emailPudoAddress}}.</p>

在电子邮件输出中,它是这样显示的。

我对 API https://mandrillapp.com/api/1.0/messages/send-template.json 的 JSON 请求是:-

valid json is `{
"key": "xxxxxxxxxxxxxxx",
"template_name": "TestTemplate",
"template_content": [],
"message": {
    "subject": "TestEmail",
    "from_email": "xxx.xx@xxxxx.in",
    "from_name": "Drop2Shop",
    "to": [{
        "Email": "xxxxx.xxx@xxxxxx.in",
        "Name": "Amrit Pannu",
        "Type": "to"
    }],
    "headers": {
        "Reply-To": "xxxxx.xxx@xxxx.in"
    },
    "important": false,
    "track_clicks": true,
    "track_opens": true,
    "merge_language": "handlebars",
    "global_merge_vars": [{
        "name": "pudoLocation",
        "content": "TRK00000028"
    },
    {
        "name": "customerName",
        "content": "TRK00000028"
    }],
    "tags": [""]
}

}`

请有人可以帮助我在这里我缺少什么? 谢谢和进步

【问题讨论】:

    标签: c# mailchimp mandrill


    【解决方案1】:

    您可以使用 *|VAR1|* 在 mandrill 中传递全局变量。要传递数组,您可以使用{{handlebars}}。 内容会是这样的:

    <p>Dear *|customerName|*,</p>
    
    <p>Thank you for using XXXXX to process your return.</p>
    
    <p>All you have to do is bring your parcel along with&nbsp;this e-mail to *|pudoLocation|* at *|emailPudoAddress|*.</p>
    

    JSON 应该是这样的:

    {
       "key": "XXXXXXXXXXXXXXX",
       "template_name": "XXXXXXXXXXXXXXXXXX",
       "template_content": [],
       "message": {
          "subject": "TestEmail",
          "from_email": "xxxx@xxxxxxxxxxx.in",
          "from_name": "xxxxxx",
          "to": [
             {
                "email": "xxxx@xxxxxxxxxxx.in",
                "name": "xxxxx xxxxx",
                "type": "to"
             }
          ],
          "headers": {
             "reply_to": "xxxx.xxxx@xxxx.in"
          },
          "important": false,
          "track_opens": true,
          "track_clicks": true,
          "merge_language": "handlebars",
          "global_merge_vars": [
             {
                "name": "trackingNumber",
                "content": "TRK00000028"
             },
             {
                "name": "customerName",
                "content": "Amrit Pannu"
             },
             {
                "name": "eCommerceRetailer",
                "content": "Jojo Retailer"
             },
             {
                "name": "goodsDescription",
                "content": "Tricycles, Scooters, and Similar Wheeled Toys; Dolls' Carriages"
             },
             {
                "name": "shippingDate",
                "content": "2021-07-07"
             },
             {
                "name": "numberOfPackages",
                "content": "45"
             },
             {
                "name": "shipFromAddress",
                "content": "IRELAND"
             },
             {
                "name": "shipToAddress",
                "content": "Britain"
             },
             {
                "Name": "pudoAddress",
                "Content": "USA"
             },
             {
                "name": "shipFromContact",
                "content": "Commin"
             },
             {
                "name": "shipToContact",
                "content": "Stark"
             },
             {
                "name": "customerReference",
                "content": "DF7889FSDHCB"
             },
             {
                "name": "pudoLocation",
                "content": "Denmark"
             },
             {
                "name": "emailPudoAddress",
                "content": "amrit@mailinator.com"
             },
             {
                "name": "unsubscribePageUrl",
                "content": ""
             },
             {
                "name": "email",
                "content": "amrit@mailinator.com"
             },
             {
                "name": "scanEventTime",
                "content": "12:07"
             },
             {
                "name": "scanEventDate",
                "content": "07 July 2021"
             },
             {
                "name": "packageItems",
                "content": [
                   {
                      "GoodsDescription": "869c6f67-f33d-4b30-a274-79b635d12461",
                      "ReturnReason": "c3b4b071-7664-4060-a39f-52c24147a1ce",
                      "Quantity": 3,
                      "Value": 6
                   },
                   {
                      "GoodsDescription": "5e2c625b-74e6-4e90-bb52-6595e9f3d088",
                      "ReturnReason": "f0949b28-f9a7-406e-8676-b8ce6c714509",
                      "Quantity": 3,
                      "Value": 14
                   },
                   {
                      "GoodsDescription": "cffe036a-2441-41af-82e1-130f9169924b",
                      "ReturnReason": "f31956b9-c24e-492e-b11f-4b4e19489b13",
                      "Quantity": 1,
                      "Value": 5
                   },
                   {
                      "GoodsDescription": "f8f64467-6926-4f08-9d4e-aa924dc1af35",
                      "ReturnReason": "d1f759b0-8e54-4119-94ee-6afe1bc49766",
                      "Quantity": 4,
                      "Value": 0
                   },
                   {
                      "GoodsDescription": "496f4e0e-739d-4fce-8a37-85113f27c4d4",
                      "ReturnReason": "b8d98439-928f-4e6c-bb56-01e6f8fb6be6",
                      "Quantity": 2,
                      "Value": 5
                   },
                   {
                      "GoodsDescription": "afe2986c-e51e-4cfe-9506-f9ef2afa5657",
                      "ReturnReason": "4e6e34f6-d921-46fb-8f4a-b04afd0856a7",
                      "Quantity": 4,
                      "Value": 12
                   },
                   {
                      "GoodsDescription": "13ac561a-d161-46a5-9795-8481e99a3afd",
                      "ReturnReason": "73f4441b-dcff-4f68-a58e-320a29a167c8",
                      "Quantity": 1,
                      "Value": 7
                   },
                   {
                      "GoodsDescription": "135e083b-0408-4445-9a0c-3656a46f7eab",
                      "ReturnReason": "325c7144-8f7d-4712-b708-1702416ca02c",
                      "Quantity": 2,
                      "Value": 13
                   },
                   {
                      "GoodsDescription": "ee510bfd-58ea-4707-9c52-26913b190b27",
                      "ReturnReason": "854629a5-289b-46c9-a072-099e2a572307",
                      "Quantity": 4,
                      "Value": 12
                   },
                   {
                      "GoodsDescription": "b6d6fa6e-a327-4014-b019-0c4cd0098da6",
                      "ReturnReason": "02394799-761c-46f0-af79-d8bc92b2c1b5",
                      "Quantity": 1,
                      "Value": 13
                   }
                ]
             },
             {
                "name": "currentYear",
                "content": 2021
             }
          ],
          "tags": null,
          "inline_css": true
       }
    

    欲了解更多信息,请参阅:https://mailchimp.com/developer/transactional/docs/templates-dynamic-content/#dynamic-content

    【讨论】:

    • @Harve Patel,我只需要使用花括号变量。因为我还需要在这里渲染一个数组,全局变量只接受字符串值。有了花括号,它以前工作得很好。但是某些设置被破坏并且停止工作。
    • 对不起,我没有检查。您能否在"merge_language": "handlebars", 之后将"merge": true, 添加到您的JSON 请求中。
    • 你好@AmritPannu,我编辑了上面的答案。 json格式也不正确。你能检查一下吗?
    • 你好@harve Patel,其实很抱歉。给定的 JSON 是错误的,因为我是从 c# 类生成的。但是我传递了正确的请求 JSON,因为 GlobalMergeVars 实际上是 global_merge_vars。我已经提到了 JSON 属性名称来给出正确的名称。是的,给定的 JSON 有问题是正确的,但在我的请求中 JSON 是正确的。我还添加了更新的 json
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    • 1970-01-01
    • 2019-04-09
    • 1970-01-01
    • 1970-01-01
    • 2015-03-01
    • 1970-01-01
    相关资源
    最近更新 更多