如何在Web应用程序中使用sendgrid发送邮件?

how to use sendgrid in web application to send mail?

我是 sendgrid 的新手,我想使用 sendgrid 从我的 Web 应用程序发送电子邮件..我尝试按照他们的文档中给出的步骤进行操作,但是 运行 我的应用程序进入无限加载

我还在我的系统中用我的键值设置了环境变量"SENDGRID_API_KEY"

这是我的代码:

        public void sendmail()
        {
            Execute().Wait();   
        }
        static async Task Execute()
        {
                var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
                var client = new SendGridClient(apiKey);
                var from = new EmailAddress("myemil@email.in", "sent");
                var subject = "Sending with SendGrid is Fun";
                var to = new EmailAddress("myemil@email.in", "received");
                var plainTextContent = "and easy to do anywhere, even with C#";
                var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
                var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
                var response = await client.SendEmailAsync(msg);
        }

尝试使用 ConfigureAwait(false):

var response = await client.SendEmailAsync(msg).ConfigureAwait(false);