我正处于设置 SendGrid 的“验证集成”阶段,并且正在使用下面的代码发送我的第一封电子邮件。我已经从他们的说明中复制了代码:
// using SendGrid's C# Library
// https://github.com/sendgrid/sendgrid-csharp
using SendGrid;
using SendGrid.Helpers.Mail;
using System;
using System.Threading.Tasks;
using System.Threading;
namespace Example
{
internal class Example
{
private static async Task Main()
{
await Execute();
Thread.Sleep(10000);
}
static async Task Execute()
{
var apiKey = "myapikey";
var client = new SendGridClient(apiKey);
var from = new EmailAddress("test@example.com", "Example User");
var subject = "Sending with SendGrid is Fun";
var to = new EmailAddress("test@example.com", "Example User");
var plainTextContent = "and easy to do anywhere, even with C#";
var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var response = await client.SendEmailAsync(msg);
}
}
}
我在一个面向 netcoreapp2.0 的控制台应用程序中运行它,来自 mac。代码运行没有错误;它说“已接受”,但我从未通过 SendGrid Web 控制台收到电子邮件。我究竟做错了什么?
编辑:PS 我是从我的本地机器上运行的,而不是从网络服务器上运行的。