

That message is then sent using the SendGridClient. Then, a SendGridMessage is created, passing in all the parameters passed into the SendGridMessage method. In SendEmailAsync, the SendGrid API key is retrieved from the application's configuration and used to create a new SendGridClient. You'll also want to log whether the emails are sent successfully, which is why the ILogger logger parameter has been added to the constructor.īoth of these parameters will be injected by ASP.NET Core's dependency injection container, and then stored as fields of the class. To send emails with SendGrid, you'll need to get the SendGrid API key from the application's configuration, which is why IConfiguration configuration has been added to the constructor parameters.

The name will be displayed to the recipient of the emails, so using the name of your website or service would make sense here. Replace with the email address you verified with SendGrid earlier, and replace with any name. but be careful about logging PII, as it increases the chance of leaking PII Adding more information related to the failed email could be helpful in debugging failure, Logger.LogInformation("Email queued successfully") Var response = await client.SendEmailAsync(msg) Var client = new SendGridClient(sendGridApiKey) įrom = new EmailAddress("", ""),

Throw new Exception("The 'SendGridApiKey' is not configured") If (string.IsNullOrEmpty(sendGridApiKey)) Public async Task SendEmailAsync(string toEmail, string subject, string message) Public SendGridEmailSender(IConfiguration configuration, ILogger logger) Private readonly IConfiguration configuration Public class SendGridEmailSender : IEmailSender The API key will now be displayed on your screen. Scroll to the bottom of the form and click Create & View. Drag the slider to the right for the Mail Send permission. Scroll down to the Mail Send accordion item and click on it to reveal the permissions underneath. For optimal security, you should only give the minimum amount of permissions that you need. You can assign different permissions to the API Key. This opens another form in the right-side panel. You can now use it to send emails! Create a SendGrid API key to send emailsīack on the SendGrid website, click API Keys under the Settings tab, then click Create API Key in the top right-hand corner. Go to your personal email inbox, open the email from SendGrid, and click Verify Single Sender. Another panel will appear on the right, asking you to confirm your email address in your email inbox. Fill out the form with your information and email address.Ĭlick Create after filling out the form. This opens a form in the right-side panel.
C how to get core id verification#
Then, click Get Started under the Single Sender Verification section. Once the settings tab opens, click Sender Authentication. To set up Single Sender Verification, click the Settings tab in the left menu. Single Sender Verification is great for testing purposes, but it is not recommended for production. This verifies that you own the email address that the application will send emails from. To quickly get started, you will use Single Sender Verification for this tutorial. Second, you’ll need to create a SendGrid API Key with permission to send emails. This will verify that you own the email address or domain that you will send emails from. There are two things you need to configure before you can send emails: First, you’ll need to set up Sender Authentication. Configure your SendGrid account to send emails Use it if you run into any issues, or submit an issue, if you run into problems.
C how to get core id code#
You can find the source code for this tutorial on GitHub.

C how to get core id free#
Sign up here to send up to 100 emails per day completely free of charge.
