gpt4 book ai didi

c# - 使用 SendGrid 安排邮件

转载 作者:行者123 更新时间:2023-12-03 01:42:45 25 4
gpt4 key购买 nike

我在 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": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7b19171a19171a3b13140f161a121755181416" rel="noreferrer noopener nofollow">[email protected]</a>",
"to": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f1939d90939d90b1999e859c90989ddf929e9c" rel="noreferrer noopener nofollow">[email protected]</a>"
}
],
"disabled": true
}

在 C# 上出现 2 个错误。我添加了 sendgrid nuget。我怎样才能通过这个错误?如果我只是在 Visual Studio 中添加 sengrid 邮件功能,它会给出“run”命名空间错误。当我将门户代码复制到此处时,它开始出现“运行”错误。

/image/ZBt4H.png

最佳答案

您应该将代码更改为

Because C# Methods must be inside a class, And class should be inside namespace

using System;
using SendGrid.Helpers.Mail;
using Microsoft.Azure.WebJobs.Host;

namespace YourProject
{
public class TempClass
{
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;
}
}
}

关于c# - 使用 SendGrid 安排邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51205023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com