response.StatusCode == UnsupportedMediaType
Issue Summary
vs2015, .net 4.6.1, nuget package SendGrid 8.0.4 response StatusCode is always UnsupportedMediaType tried it with content type "text/plain" and "text/html"
var sg = new SendGridAPIClient(ConfigurationManager.AppSettings["sendGridKey"]);
var to = new Email(emailNotification.Address);
var from = new Email(ConfigurationManager.AppSettings["emailFrom"], ConfigurationManager.AppSettings["emailDisplayName"]);
var subject = emailNotification.Subject;
var type = "text/html";
var content = new Content(type, emailNotification.Message);
var mail = new Mail(from, subject, to, content);
var response = await sg.client.mail.send.post(requsetBody: mail.Get());
Steps to Reproduce
- copy this code to an async method
Technical details:
- sendgrid-csharp Version: 8.0.4
- .NET Version: 4.6.1
@omric-axonize,
I'm guessing this is a compatibility issue with .net 4.6.1, as this library officially supports 4.5.2. We are working to provide wider support (see here), but in the mean time. I suggest you download the source and build with 4.6.1 as the target.
Please let us know how that goes. Thanks!
Hi,
I'm experiencing the same issue, but im using .NET 4.5.2. Do you have any suggestions?
@thinkingserious Thanks but I've switched to send JSON and everything works like a charm. This is my code now:
var sg = new SendGridAPIClient(apiKey);
var data = new JObject
{
new JProperty("personalizations", new JArray
{
new JObject
{
new JProperty("to",
new JArray
{
new JObject
{
new JProperty("email", emailNotification.Address)
}
}),
new JProperty("subject", emailNotification.Subject)
}
}),
new JProperty("from", new JObject {
new JProperty("email", emailFrom)}),
new JProperty("content", new JArray
{
new JObject
{
new JProperty("type", "text/plain"),
new JProperty("value", emailNotification.Message)
}
})
};
Response response = await sg.client.mail.send.post(requestBody: data.ToString());
return response.StatusCode == HttpStatusCode.Accepted;