marcus
marcus

Reputation: 29

SendGrid Webhook Event Custom Headers

While sending an email through SendGrid I am sending custom headers. I have an Function App listening to Webhook events from SendGrid. But I am not getting those custom headers back in the WebHook events. Is there a way to configure the webhooks to get the custom headers back from SendGrid ?

var client = new SendGridClient("API_KEY");
var from = new EmailAddress("[email protected]", "Example User");
var subject = "Testing with SendGrid API";
var to = new EmailAddress("[email protected]", "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);

Upvotes: 1

Views: 1586

Answers (1)

philnash
philnash

Reputation: 73075

Twilio SendGrid developer evangelist here.

When you are using the API to send emails, the best way to get properties sent back in the webhook is using custom arguments (custom_args).

You can add them to this code, by replacing AddHeaders with addCustomArgs like so:

var identifiers = new Dictionary<String, String>();
identifiers["application"] = "APP_NAME_GOES_HERE";
identifiers["resource"] = "RESOURCE_NAME_GOES_HERE";    
msg.addCustomArgs(identifiers);
var response = await client.SendEmailAsync(msg);

See the examples in the tests for more.

Upvotes: 1

Related Questions