我正在尝试通过sendgrid发送电子邮件。但是每次它返回禁止状态。
public Task SendEmailAsync(string email, string subject, string message)
{
var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
return Execute(apiKey, subject, message, email);
}
public async Task Execute(string apiKey, string subject, string message, string email)
{
var client = new SendGridClient(apiKey);
var from = new EmailAddress(Configuration["Email"], Configuration["Name"]);
var to = new EmailAddress(email);
var plainTextContent = message;
var htmlContent =message;
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var response = await client.SendEmailAsync(msg);
}
答案 0 :(得分:24)
我怀疑您尚未注册“发件人”电子邮件地址。当您尝试在其示例中发送电子邮件时,您将得到禁止的响应,因为表单地址未注册到其帐户中。假设您已经创建了一个免费帐户,请登录并转到https://app.sendgrid.com/settings/sender_auth。在页面中间,您会看到“验证单个发件人”。如果您只是探索事物,则可以使用自己的电子邮件。