I am sending an email through sendgrid Api. I want the details of response recevied from the Api.
Loading
I am sending an email through sendgrid Api. I want the details of response recevied from the Api.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sachin SinghRank #66 · 26.2K reputationPosted Feb 2, 2023, 7:48 AM EST
While creating sendgrid API, you must have given an EmailID, the same Email ID should be used in From part, To Email can be anything.
Sachin SinghRank #66 · 26.2K reputationPosted Feb 2, 2023, 6:45 AM EST
var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY"); var client = new SendGridClient(apiKey); var from_email = new EmailAddress("[email protected]", "Example User"); var subject = "Sending with Twilio SendGrid is Fun"; var to_email = new EmailAddress("[email protected]", "Example User"); var plainTextContent = "and easy to do anywhere, even with C#"; var htmlContent = "and easy to do anywhere, even with C#"; var msg = MailHelper.CreateSingleEmail(from_email, to_email, subject, plainTextContent, htmlContent); var response = await client.SendEmailAsync(msg).ConfigureAwait(false);Inside response variable you will get the response
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 2, 2023, 6:53 AM EST
Hello Gopi,
In response, it will return.
Body, Headers, StatusCode, IsSuccessStatusCode.
Thanks
Naimish Makwana
GopiRank #5,293 · 304 reputationPosted Feb 2, 2023, 7:01 AM EST
why IsSuccesStatusCode is returns as false. Also I am getting X-message id. How to get the original message id from X-message id.
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 2, 2023, 7:32 AM EST
To Get Message ID, you can get it from header.
string messageId = response.Headers["X-Message-Id"];Check this link : https://docs.sendgrid.com/glossary/what-is-x-message-id#:~:text=The%20X%2DMessage%2DID%20is,when%20sending%20email%20from%20SendGrid.&text=The%20X%2DMessage%2DID%20header,your%20X%2DMessage%2DID.
For IsSuccesStatusCode = False. Please check this.
The error exists as the email address in the "from" field in the message is not verified by sendgrid. Only put that email address in the "from" field which is explicitely verified by sendgrid.
https://stackoverflow.com/a/62375242/3054222
Thanks
Naimish