我正在构建一个Azure功能应用程序,以访问Azure队列存储(计划触发器),检索消息以及使用SendGrid发送电子邮件。
我花了很多时间调试和爬网StackOverFlow,但仍然收到相同的错误消息。
这是错误消息。
[错误]执行函数时发生异常: Functions.ScheduledMailCSharpHobby。 mscorlib:发生了异常 由调用目标抛出。 Microsoft.WindowsAzure.Storage: 设置必须采用“名称=值”的形式。
文件: run.csx
#r "SendGrid"
#r "Microsoft.WindowsAzure.Storage"
using System;
using SendGrid.Helpers.Mail;
using Microsoft.Azure;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;
public static Mail Run(TimerInfo myTimer, TraceWriter log)
{
var today = DateTime.Today.ToShortDateString();
log.Info($"Generating daily report for {today} at {DateTime.Now}");
Mail message = new Mail()
{
Subject = $"Daily Report for {today}"
};
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("serverlessbdbxxxxxxx");
// Get queue... create if does not exist.
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CloudQueue queue = queueClient.GetQueueReference("memberqueue");
// Peek at the next message
CloudQueueMessage peekedMessage = queue.PeekMessage();
// Display message.
log.Info(peekedMessage.AsString);
var mail_content = peekedMessage.AsString;
Content content = new Content
{
Type = "text/plain",
Value = $"Hi! {mail_content}"
};
message.AddContent(content);
return message;
}
文件: function.json
{
"bindings": [
{
"type": "timerTrigger",
"name": "myTimer",
"schedule": "0 0 17 * * *",
"direction": "in"
},
{
"type": "sendGrid",
"name": "$return",
"direction": "out",
"apiKey": "AzureWebJobsSendGridApiKey",
"from": "Azure Functions <samples@functions.com>",
"to": "xxxx@gmail.com"
}
]
}
答案 0 :(得分:1)
问题是由这一行引起的。
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("serverlessbdbxxxxxxx");
要访问存储帐户连接字符串,您需要