[英]how to use sendgrid in web application to send mail?
我是sendgrid的新手,我想使用sendgrid从我的网络应用程序发送电子邮件。我试图按照他们的文档中给出的步骤但是在运行时我的应用程序进入无限加载
我还在我的系统中使用我的键值设置了环境变量“SENDGRID_API_KEY”
这是我的代码:
public void sendmail()
{
Execute().Wait();
}
static async Task Execute()
{
var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
var client = new SendGridClient(apiKey);
var from = new EmailAddress("myemil@email.in", "sent");
var subject = "Sending with SendGrid is Fun";
var to = new EmailAddress("myemil@email.in", "received");
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);
}
尝试使用ConfigureAwait(false):
var response = await client.SendEmailAsync(msg).ConfigureAwait(false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.