Skip to content
ProHomeLab
RU

SSO

Setting Up Email Notifications in Authentik

Stilicho2011Updated 4 min read29 views

Also available in: RU

Part 8 of 9 in the series Authentik
  1. Authentik Overview - Architecture, Features, and Comparison with Keycloak
  2. OIDC, OAuth2, and Proxy Provider in Authentik - How to Protect Any Application
  3. Authentik - Initial Setup After Installation
  4. Setting Up Password Recovery in Authentik
  5. Setting Up User Enrollment and Invitation Processes in Authentik
  6. Setting Up Two-Factor Authentication in Authentik
  7. Cloudflare Turnstile in Authentik - Setting Up Login Form Protection
  8. Setting Up Email Notifications in Authentik
  9. Authentik - Setting Up a Reputation Policy
Contents
Tip

If you enjoyed this article, you can become a sponsor on Boosty.

I'm assuming you already have Authentik installed and configured (see the general overview and initial setup articles). In this article I'll talk about setting up email notifications in Authentik. They let you receive notifications about important events in the system - such as user logins, logouts, and authentication errors. This is useful for security monitoring and responding promptly to suspicious activity.

Configuring SMTP

Tip

For this setup, and for Authentik to work correctly in general, you need to have already configured your mail server settings in the .env environment variables file.

The block in .env looks like this (fill in the values from your mail provider):

Terminal window
AUTHENTIK_EMAIL__HOST=smtp.example.com
AUTHENTIK_EMAIL__PORT=587
AUTHENTIK_EMAIL__USERNAME=authentik@stilicho.ru
AUTHENTIK_EMAIL__PASSWORD=<mailbox_password>
# STARTTLS, usually port 587
AUTHENTIK_EMAIL__USE_TLS=true
# SSL (implicit TLS), usually port 465
AUTHENTIK_EMAIL__USE_SSL=false
AUTHENTIK_EMAIL__TIMEOUT=10
AUTHENTIK_EMAIL__FROM=authentik@stilicho.ru

After changing .env, recreate the containers: docker compose up -d.

You can verify that SMTP is configured correctly with the following command:

Terminal window
docker exec authentik_worker ak test_email your_email@domain.com

The authentik_worker container must be running, and the AUTHENTIK_EMAIL__* variables must be set correctly. If you haven't given your containers custom names via container_name, do the same thing through the service name: docker compose exec worker ak test_email your_email@domain.com.

Common mistakes that keep the test email from going out:

  • USE_TLS and USE_SSL both enabled. Pick one: USE_TLS=true for STARTTLS (usually port 587) or USE_SSL=true for SSL (usually port 465).
  • Password in quotes. Quotes in .env become part of the password, and authentication fails.
  • A single underscore in the variable names instead of two. It's AUTHENTIK_EMAIL__HOST, with a double underscore after EMAIL.
  • Your hosting provider blocks outgoing SMTP ports. Many VPS providers close ports 25/465/587 by default - in that case no settings will get the email out, and you need either a support request or an SMTP relay on a different port.
  • The address in AUTHENTIK_EMAIL__FROM doesn't match the mailbox you authenticate as. Many mail services reject such messages.

Setting up event notifications

Note

The application settings described in this article are accurate as of the time of writing.

Log in to Authentik as an administrator and go to:

Events → Notification Rules

List of Notification Rules in Authentik

In this article I'll show notification setup for only three basic events, which I consider the most important from a security standpoint. If needed, you can configure any other events you like.

Click Create. In the window that appears, give the rule a name that makes sense to you. In my case, this is a rule for monitoring logins to Authentik.

In the Groups section, specify which group's users will receive the notifications. In my case, this is authentik Admins.

In the Transport section, choose the notification delivery mechanism. In this case, email is used - the built-in default-email-transport, which sends mail through the global SMTP settings from .env. Next to it there's default-local-transport, which shows notifications right in the Authentik UI; you can select both at once.

Keep in mind: with no recipient, the notification simply isn't created. The rule will fire just fine, but you'll never see an email unless a group is selected under Groups (or the Send notification to event user option is on, which notifies the user the event is about).

In the Severity section, choose the importance level of the event. I use the Alert value, then click Create.

Notification Rule creation window - name, group, transport, severity

Go to the rule we just created and click Create and Bind Policy.

Empty list of policies bound to the rule - Create and Bind Policy button

In the window that appears, select Event Matcher Policy.

Selecting the policy type - Event Matcher Policy

Give the policy a name (for example, login). In the Action section, choose the event that will trigger the notification. In my case, this is Login.

The remaining parameters depend on your requirements - they're described in more detail in the official documentation. If your goal is simply to get notified about the event without additional filtering, you can leave them unchanged, as shown in my screenshot.

Configuring the Event Matcher Policy - name login and Action Login

In the next window, set the processing order for the policy. I start with a value of 10 and click Finish.

Creating the policy binding - Order 10, Enabled, Finish

To keep track of key user actions (or potential attackers), I create two more similar policies. The only difference is the event type:

  • Logout
  • Login Failed

Event Matcher Policy for the Logout event

Event Matcher Policy for the Login Failed event

As a result, the list of bound policies looks roughly like this:

Final list of bound policies - login, logout, login-failure

The rule fires when an event matches any of the bound policies, so a single rule with three policies covers all three events.

Once configured, it's recommended to run a test. To do this, you can log out and log back into Authentik, and also try logging in with incorrect credentials. If everything is set up correctly, an email notification will arrive for each corresponding event.

Notifications only tell you about failed logins - they don't stop them. To have Authentik actually react to password guessing, by showing a CAPTCHA or shutting the login down altogether, see the articles on the Reputation Policy and Cloudflare Turnstile.