【发布时间】:2018-07-06 07:21:20
【问题描述】:
我是在 Azure 门户上制作的,如何转换为用 C# 发送这个预定邮件?
run.csx 的样子;
#r "SendGrid"
using System;
using SendGrid.Helpers.Mail;
using Microsoft.Azure.WebJobs.Host;
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 = "15 DK'LIK TEST MAILI"
};
Content content = new Content
{
Type = "text/plain",
Value = "Bu mail 15 dk da bir yinelenecektir."
};
message.AddContent(content);
return message;
}
function.json 看起来像;
{
"bindings": [
{
"type": "timerTrigger",
"name": "myTimer",
"schedule": "0 */15 * * * *",
"direction": "in"
},
{
"type": "sendGrid",
"name": "$return",
"direction": "out",
"apiKey": "CustomSendGridKeyAppSettingName",
"from": "blabla@hotmail.com",
"to": "blabla@hotmail.com"
}
],
"disabled": true
}
在 C# 上给出 2 个错误。我添加了 sendgrid nuget。我怎样才能通过这个错误?如果我只是在 Visual Studio 中添加 sengrid 邮件功能,它会给出“运行”命名空间错误。当我在这里复制我的门户代码时,它开始出现“运行”错误。
【问题讨论】:
-
请注意,Visual Studio 是代码编辑器的名称(就像记事本是文本编辑器,或者 Excel 是电子表格编辑器)。
visual-studio标记只能用于与编辑器本身有关的问题,而不是仅使用 Visual Studio 编写的代码。 -
您已将代码直接放入
.cs文件中,而不是放入命名空间和类中。 -
哦。非常感谢。我是新手。我没有注意到这段代码中没有类:D
-
Ridanod 不客气 :) 祝你的项目好运。