1

Issue Summary

Response: Bad request

Not able to send mail from MVC c# web application : getting following error Response: Bad request : using "SendEmailAsync" Response: Id = 8, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}" using "RestClient"

Steps to Reproduce

  1. Use the above code in any MVC application with out static class
  2. Run the code
  3. same error will be thrown.

Code Snippet

//RestClient -- var client = new RestClient("https://api.sendgrid.com/v3/mail/send");
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                request.AddHeader("Authorization", "Bearer Sendgridtoken");
                request.AddHeader("Content-Type", "application/json");
                request.AddParameter("application/json", "{\"personalizations\":[{\"to\":[{\"email\":\"jhon@abc.com\"}]}],\"from\":{\"email\":\"asd@xyz.com\"},\"subject\":\"testing login\",\"content\":[{\"type\":\"text/plain\",\"value\":\"tesing login login\"}]}", ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);
                Console.WriteLine(response.Content);

Exception/Log

using "SendEmailAsync" Response: Id = 8, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}" using "RestClient" Response: Bad request ``

Technical details:

  • sendgrid-csharp version: SendGrid 9.22.0
  • csharp version: 4.5

Note :

We are not using any static method for this implementation We are not using this as a back job, we are implementing this as a method.

Blake
  • 259
  • 5
  • 23
  • The sendgrid client uses `async` requests, which you have to `await`. Your log shows, you are not doing that (despite not showing any code how you use the sendgird client) – derpirscher Dec 29 '20 at 18:22
  • And with the RestClient response: Typically responses from sendgrid, especially with errors, contain more than just a status code but also a body which contains one or more error messages – derpirscher Dec 29 '20 at 18:28
  • Check if there is a `response.ErrorMessage` or `response.ErrorException` property which should explain whats wrong. – derpirscher Dec 29 '20 at 18:44
  • You could also try to do the same request with Postman and look at the response body – derpirscher Dec 29 '20 at 18:45

0 Answers0