This article will discuss about sending emails with dynamic templates from SendGrid with ASP.NET Core. SendGrid will help you to configure and send emails from your apps using SMTP API and SendGrid API. SendGrid also helps you to design and configure email templates from their admin portal. In one of applications I am building I am using Azure B2C - which currently supports custom from email address with the help of SendGrid. You can find more details about how to configure it from here. So first you need to create dynamic template from SendGrid. You can create it from https://mc.sendgrid.com/dynamic-templates. You can create the template either using Code Editor or Design Editor.
You can put the place holders inside double curly braces like this ``. Please note it is
Once you create it, you need to note down the template id, which is required to use in the code. Next you need to create an API Key, which you can do it from API Keys section - https://app.sendgrid.com/settings/api_keys. You need to select only
Mail Send access details only. You need this also in the code.
Once you completed these two steps, you can start writing code. To use
SendGrid API, you need to add the
SendGrid package - with this command -
dotnet add package SendGrid. And here is the code.
Happy Programming :)