SendGridForEpi fixed to work with CMS 12

The versions published on Optimizely's NuGet now has a version 2.0.2 that is compatible with .NET 6.0 and CMS 12.4.2 or newer.

Once upon a time I created this package that handles SendGrid messages asynchronously. The typical use case is probably when you have a subscription feature and want to send e-mails to subscribers from an Optimizely Content Cloud app through SendGrid and use Handlebars with their template designer.

It has a sort of local queue and scheduled job that processes it.

Some quick notes from upgrading:

  1. Given the amount of code it seemed easiest to not upgrade anything and instead create empty .NET 6.0 class libraries and then move code over.
  2. Removed the .nuspec files and moved over to package settings within the .csproj file.
  3. Chose to take dependencies on EPiServer.CMS.AspNetCore (≥ 12.4.2 && < 13.0.0) and EPiServer.Framework.AspNetCore (≥ 12.4.2 && < 13.0.0) instead of the wrapping EPiServer.CMS package.

If you have used the package with CMS 11 there are no changes in the database tables. The only thing you need to set up is the new way of configuring the connection string and the SendGrid API Key when using DI.

In Startup.cs and inside ConfigureServices(), add these lines. Replace the connection string with the SQL Server database that you want to use.

In most cases you would have these secret values in environment variables and fetched through IConfiguration.

// Set the SendGrid API Key
services.AddSendGrid(options => { options.ApiKey = "your-key-that-usually-starts-with-SG."; });

// Add a connection string for some SQL Server db
var mailService = new SqlServerMailService("a-sql-server-connection-string");

// Check that the tables are in database
mailService.CreateTablesIfNeeded();

// Register it
services.AddSingleton<IMailService>(mailService);

Check the Github README on how to construct a message and work the personalization variables.

Published and tagged with these categories: Episerver, ASP.NET, Development