[英]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.