Reputation: 379
SendGrid advises using its Version 6.3, but that only supports .NET 4.5 ; My app is 4.6.1 and is serving on an Azure app service.
I want to try to send smtp through SendGrid and see only this page for documentation. It does not show how to write the message in the IdentityConfig class and it does not say how/where to reference the SendGrid apikey via Azure's Environment Variable storage https://sendgrid.com/docs/Integrate/Code_Examples/v2_Mail/csharp.html#-Using-NETs-Builtin-SMTP-Library.
I'd really appreciate some help on this.
Upvotes: 0
Views: 1118
Reputation: 379
I looked again at the SendGrid documentation and saw that the updates in late 2017 didn't say that the api only targeted 4.5.*, so decided to try the most recent version, 9.8 .
It worked with the Register Post method out of the box, simply adding a redirect to a "confirmationsent" view.
Here's the code that works for me:
public Task SendAsync(IdentityMessage message)
{
return configSendGridasync(message);
}
private async Task configSendGridasync(IdentityMessage message)
{
var apiKey = System.Environment.GetEnvironmentVariable("SENDGRID_APIKEY");
var client = new SendGridClient(apiKey);
var msg = new SendGridMessage();
msg.AddTo(message.Destination);
msg.From = new EmailAddress("[email protected]", "Website Name");
msg.Subject = message.Subject;
msg.PlainTextContent = message.Body;
msg.HtmlContent = message.Body;
var response = await client.SendEmailAsync(msg);
}
}
Upvotes: 2