Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


NuGet distributed packages for Episerver that handles async API-posting by a "local" queue storage and a Scheduled Job securing successful posts.


Packages are in Episerver's NuGet feed. If not set up go to Visual Studio => NuGet Package Manager => Package Sources => Add

Install-Package Krompaco.SendGridForEpi.SqlServer

This package will install both packages needed. Minimum Episerver version is 11.10.6 and SendGrid package is 9.10.0.


The main package requires you to add an app setting for the API Key. The key needs Mail Send Access and you set this up in Settings => API Keys in SendGrid.

<add key="sendgridforepi:ApiKey" value="" />

When using the Krompaco.SendGridForEpi.SqlServer package you have the option to use another connection string name than EPiServerDB. If not present or empty "EPiServerDB" will be used. Two tables named SendGridForEpiMailQueue and SendGridForEpiMailQueueArchive will be created on startup if not already present in the configured database.

<add key="sendgridforepi:SqlServerConnectionStringName" value="MyOwnDB" />

How it works

You add SendGridMessage (from the offical package) objects to a queue that is then processed and posted to the SendGrid API by a scheduled job. If error occurs job will try again next execution and log the number of attempts and latest error message.

The implementation handles batching of more than 1000 personalizations internally so you don't need to think about that limit.

My recommended approach is to hold mail templates and as much content as possible in SendGrid and work with Handlebars syntax. Posting through the API with SendGrid edited templates will automatically use template images to track mails opened and also rewrite links in your content so that clicks are tracked.

In the following example I have put the Subject line and the Body in SendGrid's template editor and use this model for the dynamic data.

private class CommentTemplateData
    public string WhoIs { get; set; }

    public string CommentText { get; set; }

In the SendGrid template I will use Handlebars to output the data above using {{whoIs}} and triple-stash for the HTML property {{{commentText}}}.

var mail = new SendGridMessage
    From = new EmailAddress(""),
    TemplateId = "the-id-found-in-the-sendgrid-template-editor",
    Personalizations = new List<Personalization>()

    new Personalization()
        Tos = new List<EmailAddress>
                    new EmailAddress("")
                TemplateData = new CommentTemplateData
                    WhoIs = "Some Name",
                    CommentText = "<p>First line of comment.</p><p>Second line of comment.</p>",

this.mailService.AddToQueue(new MailQueueItem
    Date = DateTime.UtcNow,
    Mail = mail

Assuming this code was in a Controller you would have gotten hold of the IMailService implementation in the constructor.

private readonly IMailService mailService;

public ArticlePageController(IMailService mailService)
    this.mailService = mailService;


Async API-posting by local queue storage and a Episerver Scheduled Job securing successful posts





No packages published
You can’t perform that action at this time.