【发布时间】:2019-05-12 20:07:04
【问题描述】:
我正在使用 SendGrid 发送确认邮件以确认电子邮件,但是 ApiKey 始终为空
public Task SendAsync(IdentityMessage message)
{
var ApiKey = Environment.GetEnvironmentVariable("ApiKeyFromSendGrid");
var client = new SendGridClient(ApiKey);
var from = new EmailAddress("XXX@gmail.com", "Any Name");
var subject = "Sending with SendGrid is Fun";
var to = new EmailAddress(message.Destination, "Any Name");
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 = client.SendEmailAsync(msg);
return response;
}
错误在哪里? enter image description here
【问题讨论】:
-
表示该key的环境变量不存在。检查密钥是否正确。调试。
-
如何检查变量是否存在?
-
为此使用环境变量似乎很奇怪。为什么不将值存储在 .config 文件中?
标签: c# asp.net-mvc sendgrid