首页 > 解决方案 > 使用自定义标头通过 F5 重定向 SendGrid Webhook 事件

问题描述

通过 SendGrid 发送电子邮件时,我正在发送自定义标题。有没有办法配置 webhook 以从 SendGrid 获取自定义标头,以便可以轻松编写 F5 iRule 以根据此自定义标头中的值重定向流量。我知道我可以使用 .addCustomArgs(...) 返回自定义数据,但我想要标题中的自定义数据。

var client = new SendGridClient("API_KEY");
var from = new EmailAddress("test@example.com", "Example User");
var subject = "Testing with SendGrid API";
var to = new EmailAddress("joe@test.com", "Example User");
var plainTextContent = "Test Content";
var htmlContent = "<strong>Testing with HTML content</strong>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var identifiers = new Dictionary<String, String>();
identifiers["application"] = "APP_NAME_GOES_HERE";
identifiers["resource"] = "RESOURCE_NAME_GOES_HERE";    
msg.AddHeaders(identifiers);   
var response = await client.SendEmailAsync(msg);

标签: sendgridf5

解决方案


Twilio SendGrid 开发人员布道者在这里。

恐怕您无法为 SendGrid 事件 webhook 设置标头以发回。自定义参数作为 JSON 正文的一部分发送。

我以前没有使用过 F5 iRules,但您似乎可以在 iRule 中解析和使用请求的 JSON 正文。根据这篇文章,您可以使用 iRules LX 来处理使用 JavaScript 的 JSON

或者看起来你可以结合HTTP::collect一个HTTP_REQUEST_DATA来收集和处理请求体。


推荐阅读