I am trying to send email using SendGrid
on Azure
.
I followed these instructions: https://learn.microsoft.com/tr-tr/azure/sendgrid-dotnet-how-to-send-email ; but it doesn't seem to work.
. Sending via smtp
works though.
using System;
using System.Threading.Tasks;
using SendGrid;
using SendGrid.Helpers.Mail;
namespace Example
{
internal class Example
{
private static void Main()
{
Execute().Wait();
}
static async Task Execute()
{
var apiKey = System.Environment.GetEnvironmentVariable("SENDGRID_APIKEY");
var client = new SendGridClient(apiKey);
var msg = new SendGridMessage()
{
From = new EmailAddress("from@hotmail.com", "DX Team"),
Subject = "Hello World from the SendGrid CSharp SDK!",
PlainTextContent = "Hello, Email!",
HtmlContent = "<strong>Hello, Email!</strong>"
};
msg.AddTo(new EmailAddress("to@gmail.com", "Test User"));
var response = await client.SendEmailAsync(msg);
}
}
}