Search code examples
.net-coresendgrid

passing custom message id parameter in sendgrid while sending email and how can it be get from webhook


I am trying to passing custom message id (X-Message-Id) from while sending email. var client = new SendGridClient(apiKey);

            var msg = new SendGridMessage()
            {
                From = new EmailAddress("test@gmail.com", "Ravi Kumar"),
                Subject = "Sending with Twilio SendGrid is Fun",
                HtmlContent = "<body><a href='http://www.sendgrid.com'>SendGrid</a></body>",
               
            };
            msg.AddTo(new EmailAddress("test@gmail.com", "Ravi CIPL"));

How can i pass custom X-Message-Id to sendgrid that can be get from the webhook event.


Solution

  • You can add a header to an email in SendGrid C# using the msg.AddHeader method:

    var msg = new SendGridMessage()
    {
        From = new EmailAddress("test@gmail.com", "Ravi Kumar"),
        Subject = "Sending with Twilio SendGrid is Fun",
        HtmlContent = "<body><a href='http://www.sendgrid.com'>SendGrid</a></body>",           
    };
    msg.AddTo(new EmailAddress("test@gmail.com", "Ravi CIPL"));
    msg.AddHeader("X-Message-ID", myMessageId);