【问题标题】:dynamic_template_data doesn't work with sendgrid and azure function integrationdynamic_template_data 不适用于 sendgrid 和 azure 函数集成
【发布时间】:2018-10-23 15:03:47
【问题描述】:

尝试使用带有 azure 函数 sendgrid 集成 (javaScript) 的事务模板,我正在发送以下对象(已删除电子邮件地址等):

const message = 
{  
   "personalizations":[  
      {  
         "to":[  
            {  
               "email":"[MY_EMAIL]",
               "name":"Rotem"
            }
         ],
         "dynamic_template_data":{  
            "rotem_test1":"wow"
         }
      }
   ],
   "from":{  
      "email":"[FROM_EMAIL]",
      "name":"name"
   },
   "reply_to":{  
      "email":"[REPLY_EMAIL]",
      "name":"name"
   },
   "template_id":"[CORRECT_TEMPLATE_ID]",
   "tracking_settings":{  
      "click_tracking":{  
         "enable":true
      }
   }
}
context.done(null,message);

还尝试使用 context.done(null,JSON.stringify(message)) 得到相同的结果: 我收到一封来自正确模板的电子邮件,但没有任何替换。

当使用https://api.sendgrid.com/v3/mail/send 发送完全相同的对象时 使用邮递员的 API 一切正常。

很想在这里获得帮助,了解我在 azure 函数上做错了什么。

【问题讨论】:

  • 有什么进展吗?如果您还有其他问题,请随时询问。
  • 感谢您的解决方案!完美运行。

标签: azure azure-functions sendgrid sendgrid-templates


【解决方案1】:

您做的一切都正确,因为您可以按预期收到电子邮件。

问题是由 SDK 版本引起的。 dynamic_template_data是最新的9.10.0 Sendgrid C# SDK中刚刚添加的属性,但是绑定扩展仍然使用旧版本,不知道dynamic_template_data是什么。

对于 2.x 功能(检查 Azure 门户上的功能应用设置,请参阅运行时版本:2.xxx (~2)),我们可以在更新扩展之前手动安装新版本的 SDK。

如果你在本地开发

  1. 进入函数工程目录,删除bin、obj文件夹。
  2. 编辑function项目下的extensions.csproj,添加最新版本的Sendgrid<PackageReference Include="Sendgrid" Version="9.10.0" />
  3. 在该目录下打开控制台(终端、Powershell等),输入func extensions install恢复包。

Azure 门户上的其他内容

  1. 停止函数应用。
  2. 通过Platform Features -> Advanced Tools(Kudu) -> Debug Console (CMD)访问kudu控制台
  3. 导航到 D:\home\site\wwwroot
  4. 删除bin目录
  5. 编辑 extensions.csproj,添加 <PackageReference Include="Sendgrid" Version="9.10.0" /> 并保存更改。
  6. 在下面的控制台中,输入dotnet build extensions.csproj -o bin --no-incremental --packages D:\home\.nuget
  7. 看到Build succeeded后,启动函数应用。

对于 1.x 功能(Runtime ~1),恐怕我们必须手动使用 sendgrid node module 发送电子邮件,1.x 功能中的 Sendgrid 版本被锁定,因此无法更新。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-15
    • 1970-01-01
    相关资源
    最近更新 更多