DocumentationDiscussions
DocumentationDiscussions

Notifying with Email

Have Seq send email notifications when certain events arrive or alerts are triggered.

Seq can automatically send email when events are logged – this is accomplished using the Email+ app Seq.App.EmailPlus.

Installing and Configuring the Email+ App

This app supports simple formatted email with {{Handlebars}} templates for rendering event properties into the subject and body.

Installing the Package

The package id of this app is Seq.App.EmailPlus. In Seq, go to settings > Apps and select Install from NuGet. You'll be presented with a dialog requesting the package id. Type it in, and press Install.

12801280

Installing Seq.App.EmailPlus

After a short wait, the app will appear in the Apps list. To use the app, configure it by creating an instance.

App instances

To the right of the app's name in the app list, select the link titled Start a new instance.... This will present a configuration page where settings can be applied to the app.

Here’s how configuration for the Email+ app looks:

12801280

The top section is where the instance is given a name, and the source of events is configured.

Further down, in the Settings section, you see some pretty typical fields for configuring email.

The Default Template

Once the app is installed and an instance configured, you're all set to send email: the app comes with a simple template out of the box that turns this event:

12801280

Into an HTML email like this:

11081108

The template will show the details of the event including its timestamp, level, message and properties.

📘

For development and testing of email templates, we use the excellent Papercut local email server/viewer.

Linking Back to your Seq Server

The email sent by Seq includes a link back to view the event on the Seq server. This uses the address on which Seq is configured to listen - http://localhost:5341 by default.

To set a different address, either set the SEQ_API_CANONICALURI environment variable to the public address of your Seq server (great for Docker), or use the Seq command-line on Windows to set api.canonicalUri:

seq config set -k api.canonicalUri -v https://your-seq-server
seq service restart

Writing Handlebars Templates

If you would like to send email with a different body, you can provide an HTML template using Handlebars syntax.

📘

Looking for an example?

The default template itself is published on GitHub for you to read and modify.

To include a property like CartSize in the email body, simply include it in double-braces:

<p>A new sale was processed for {{CartSize}} items.</p>

Built-in Properties

In addition to the properties from the event payload, a number of built-in properties provide access to the event's metadata. These are prefixed with a dollar sign and include:

NameDescription
$EventTypeThe type assigned to the event, for example $00COFFEE
$ExceptionThe full text of the exception attached to the event, if any, including stack trace
$IdThe event's id, for example event-1234...abcd
$LevelVerbose, Debug, Warning, Error, or Fatal
$LocalTimestampThe local timestamp attached to the event including timezone offset
$InstanceThe instance name of the Seq server sending the email, if any
$MessageThe rendered message text for the event
$MessageTemplateThe message template for the event
$PropertiesA list of Name/Value pairs describing the event's properties; see below
$ServerUrlThe Seq server's listening URL
$UtcTimestampThe UTC timestamp of the event

Enumerating event properties

To list properties attached to the event, use the Handlebars each construct. Property objects have a name and a value; there's a built-in helper called "pretty" that can format complex objects if necessary.

<ul>
  {{#each $Properties}}
  <li>{{@key}} is {{pretty this}}</li>
  {{/each}}
</u>

📘

Important Note

The first email app written for Seq is called Seq.App.Email. This is now deprecated, but still published so that users of that version can continue receiving updates and bug fixes. The newer app, described here, is Seq.App.EmailPlus.


What’s Next