Reputation: 305
I've upgraded from v2 to v3 and (C# implementation) of SendGrid. I can get it to send mail, but it just hangs in the code after doing so on the last line:
dynamic sendGridAPIClient = new SendGridAPIClient(SendGridApi);
Email from = new Email(EmailAddress, EmailName);
Email to = new Email(EmailAddress, EmailName);
Content content = new Content("text/html", message);
Mail mail = new Mail(from, subject, to, content);
dynamic response = sendGridAPIClient.client.mail.send.post(requestBody: mail.Get());
It's annoying because it goes into a black hole with that function and you can't debug it unlike v2 which worked just fine.
Upvotes: 1
Views: 1606
Reputation: 921
If you can't use await
, try this instead:
var response = sendGridAPIClient.client.mail.send.post(requestBody: mail.Get())
.GetAwaiter().GetResult();
Note that a response.StatusCode
of OK (200)
, rather counter-intuitively, means SendGrid have thrown the mail message into the void.
You want a StatusCode
of Accepted (202)
, which means it's been queued for delivery.
Upvotes: 1
Reputation: 1
It is an Asynchronous Call, so try this:
dynamic response = await sendGridAPIClient.client.mail.send.post(requestBody: mail.Get());
Upvotes: 0