【问题标题】:Using SendGrid in Azure worker role在 Azure 辅助角色中使用 SendGrid
【发布时间】:2017-10-04 18:44:58
【问题描述】:

谁能告诉我 SendGrid 是否可以在不使用 .net 核心的 Azure 辅助角色项目中使用?知道什么更适合使用 sendgrid 进行通知也会很好。辅助角色或网络作业或 Azure 函数?

尝试在非 .NET Core 的项目中使用它时,我在创建 sendgrid 客户端时收到以下错误:

“SendGrid.dll 中的‘System.IO.FileNotFoundException’”

谢谢

-拉维

【问题讨论】:

  • 当尝试使用什么?尝试提供代码 sn-p 和一些上下文,不要让我们悬而未决。

标签: azure sendgrid azure-worker-roles


【解决方案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);
            }
    }

最好知道什么更适合使用 sendgrid 进行通知。辅助角色或网络作业或 Azure 函数?

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-24
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    • 2011-08-22
    • 2014-11-09
    • 1970-01-01
    相关资源
    最近更新 更多