So i have a bit of a weird things going on. I'm trying to get SendGrid v9 working on my web app. I've run this through a bunch of test, including creating a console app to test. It works great in the console app but hangs in the web app. I'm obviously missing something - possibly to do with the async call, but really looking for an assist:
My console app:
namespace Example
{
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using SendGrid;
using SendGrid.Helpers.Mail;
using System.Collections.Generic;
using System.Diagnostics;
internal class Example
{
private static void Main()
{
Execute().Wait();
}
static async Task Execute()
{
var client = new SendGridClient("[MYKEY]");
// Send a Single Email using the Mail Helper
var from = new EmailAddress("my@email.com", "Example User");
var subject = "Hello World from the SendGrid CSharp Library Helper!";
var to = new EmailAddress("my@email.com", "Example User");
var plainTextContent = "Hello, Email from the helper [SendSingleEmailAsync]!";
var htmlContent = "<strong>Hello, Email from the helper! [SendSingleEmailAsync]</strong>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var response = await client.SendEmailAsync(msg);
Debug.WriteLine(msg.Serialize());
Debug.WriteLine(response.StatusCode);
Debug.WriteLine(response.Headers);
}
}
}
My web app:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
using System.Threading.Tasks;
using Newtonsoft.Json;
using SendGrid;
using SendGrid.Helpers.Mail;
namespace WebAppTest
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Execute().Wait();
}
public static async Task Execute()
{
var client = new SendGridClient("[MYKEY]");
// Send a Single Email using the Mail Helper
var from = new EmailAddress("my@email.com", "Example User");
var subject = "Hello World from the SendGrid CSharp Library Helper!";
var to = new EmailAddress("my@email.com", "Example User");
var plainTextContent = "Hello, Email from the helper [SendSingleEmailAsync]!";
var htmlContent = "<strong>Hello, Email from the helper! [SendSingleEmailAsync]</strong>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var response = await client.SendEmailAsync(msg); //It hangs on this call
Debug.WriteLine(msg.Serialize());
Debug.WriteLine(response.StatusCode);
Debug.WriteLine(response.Headers);
}
}
}
These are blank project, nothing much in the web.cofigs or app.configs
What am i missing. Why is the web app not functioning with this but the console app does?
TIA