Send Mail Using SendGrid In .NET Core
This post is about sending emails using Send Grid API in .NET Core. SendGrid is a cloud-based SMTP provider that allows you to send email without having to maintain email servers. SendGrid manages all of the technical details, from scaling the infrastructure to ISP outreach and reputation monitoring to whitelist services and real time analytics.
If you are an azure subscriber, SendGrid comes with a Free Plan, which helps you to try SendGrid in your application. Once you configured, from Azure portal you will get the details to configure your SMTP server details.
In ASP.NET Core 2.0, you can use this to send email using
In this post I am going to use SendGrid API. For that first you need to install the SendGrid nuget package as your reference. You can do this by modifying the CSProj file or using
dotnet add package command. Here is the CSProj file with SendGrid package.
To use API, first you need to get SendGrid API key, you can click on the Manage option in the Azure portal, which will redirect you to SendGrid portal. You can generate an API key from Settings > API Keys. You need to select email sending permission only. Once you generate the API Key, you can use the following code to send email.
SendGrid mail helper requires plain text and html content, so I am using a RegEx to clean up my HTML and making it plain text.
Happy Programming :)