在Azure辅助角色中使用SendGrid

时间:2017-10-04 18:44:59

标签: azure sendgrid azure-worker-roles

有人能告诉我SendGrid是否可以在不使用.net核心的Azure工作者角色项目中使用?了解使用sendgrid进行通知更好的方法也很好。工作者角色或Web作业或Azure功能?

尝试在不是.NET Core的项目中使用它时,在创建sendgrid客户端时出现以下错误:

"' System.IO.FileNotFoundException'在SendGrid.dll"

由于

-Ravi

1 个答案:

答案 0 :(得分:1)

  

有人可以告诉我SendGrid是否可以在不使用.net核心的Azure辅助角色项目中使用?

它应该在Azure辅助角色中起作用。我也做了一个测试,它在我身边正常工作。以下是演示代码。

 private async Task RunAsync(CancellationToken cancellationToken)
 {
            var apiKey = "sendgrid APIkey";
            var client = new SendGridClient(apiKey);

            // TODO: Replace the following with your own logic.
            while (!cancellationToken.IsCancellationRequested)
            {
                Trace.TraceInformation("Working");

                var msg = new SendGridMessage
                {
                    From = new EmailAddress("send email", "Sunguiguan"),
                    Subject = "Hello World from the SendGrid CSharp SDK!",
                    PlainTextContent = "Hello, Email!",
                    HtmlContent = "<strong>Hello, Email!</strong>"
                };
                msg.AddTo(new EmailAddress("another email", "test user"));
                client.SendEmailAsync(msg, cancellationToken).Wait(cancellationToken);

                await Task.Delay(1000*60, cancellationToken);
            }
    }

enter image description here

  

了解使用sendgrid进行通知更好的方法也很好。工作者角色或Web作业或Azure功能?

所有这些服务都可以使用sendgrid进行通知。这取决于你想要的。我们可以参考Azure Webjobs vs Azure Functions : How to chooseAzure App Service, Virtual Machines, Service Fabric, and Cloud Services comparison来获取更多信息。