[英]Azure SendGrid The provided authorization grant is invalid, expired, or revoked
I have created a built in azure function to send email using SendGrid from the available options in azure, here is my code I have created a built in azure function to send email using SendGrid from the available options in azure, here is my code
I used develop in portal option from azure我在 azure 的门户选项中使用了开发
// The 'From' and 'To' fields are automatically populated with the values specified by the binding settings.
//
// You can also optionally configure the default From/To addresses globally via host.config, e.g.:
//
// {
// "sendGrid": {
// "to": "user@host.com",
// "from": "Azure Functions <samples@functions.com>"
// }
// }
#r "SendGrid"
using System;
using SendGrid.Helpers.Mail;
using Microsoft.Azure.WebJobs.Host;
public static SendGridMessage Run(Order order, ILogger log)
{
log.LogInformation($"C# Queue trigger function processed order: {order.OrderId}");
SendGridMessage message = new SendGridMessage()
{
Subject = $"Thanks for your order (#{order.OrderId})!",
From = new EmailAddress("from@outlook.com"),
};
message.AddTo(order.CustomerEmail, order.CustomerName);
message.AddContent("text/plain", $"{order.CustomerName}, your order ({order.OrderId}) is being processed!");
return message;
}
public class Order
{
public string OrderId { get; set; }
public string CustomerName { get; set; }
public string CustomerEmail { get; set; }
}
I have my json as follows我的 json 如下
{
"bindings": [
{
"type": "queueTrigger",
"name": "order",
"direction": "in",
"queueName": "samples-orders"
},
{
"type": "sendGrid",
"name": "$return",
"direction": "out",
"apiKey": "FUNCTIONS_EXTENSION_VERSION"
}
]
}
When I manually trigger it I am getting an error as mentioned I tried changing the api key but some how it is resetting当我手动触发它时,我收到一个错误,如前所述,我尝试更改 api 键,但有些如何重置
Can some one help me how to resolve the error有人可以帮我解决错误吗
If I recall correctly, you should set the name of your SendGrid API key AppSetting to the apiKey
parameter in the SendGrid binding.如果我没记错的话,您应该将 SendGrid API 键 AppSetting 的名称设置为 SendGrid 绑定中的
apiKey
参数。 So instead of "apiKey": "FUNCTIONS_EXTENSION_VERSION"
it should be "apiKey": "MySendGridApiKey"
or replace MySendGridApiKey
with whatever name you'd like to give the AppSetting.因此,应该是
"apiKey": "MySendGridApiKey"
,而不是"apiKey": "FUNCTIONS_EXTENSION_VERSION"
,或者将MySendGridApiKey
替换为您希望为 AppSetting 提供的任何名称。
Then, in your Azure Function AppSettings, create an AppSetting with the same name and set the value to your SendGrid API key.然后,在您的 Azure Function AppSettings 中,创建一个具有相同名称的 AppSetting 并将值设置为您的 SendGrid API 键。
You can read more about creating your API Key here , and read more about managing AppSettings in Azure Functions here .您可以在此处阅读有关创建 API 密钥的更多信息,并在此处阅读有关在 Azure 函数中管理 AppSettings 的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.