New mail notification through NTFY or GOTIFY or similar

Your question

Is there any way to trigger a HTTP URL on new mail? I’m thinking about NTFY or GOTIFY notification services (selfhosted). I thought perhaps sieve could be used? That way it could be setup to only be triggered for certain (high importance) mails.

There is no built-in “HTTP notify” action for per-user Sieve filters. What’s available:

1. Sieve exec (admin/trusted scripts only)
Stalwart’s Sieve dialect adds an exec function that runs an external program (e.g. curl) and returns true/false based on exit status. This works only in trusted Sieve scripts (the ones the admin attaches to SMTP stages such as RCPT/DATA), not in per-user Sieve filters, so a mail admin could write a stage script that inspects the message (e.g. an Importance: high header) and shells out to curl to hit an ntfy/Gotify endpoint:

require "vnd.stalwart.expressions";

if header :contains "Importance" "high" {
    if eval "!exec('/usr/bin/curl', ['-d', 'New high-importance mail', 'https://ntfy.example.com/mytopic'])" {
        # exec failed
    }
}

The regular notify extension available to normal user Sieve filters is restricted to the mailto URI scheme by default (configurable via allowedNotifyUris), so it can’t be used to hit an arbitrary webhook URL.

2. Webhooks (server-wide, not per-message-content)
Stalwart also has a server-level Webhooks feature that POSTs JSON to an HTTP endpoint whenever selected server events occur (e.g. message received/delivered). This is configured as a WebHook object under Settings › Telemetry › Webhooks, but it triggers on event type, not on message content like importance, so it can’t selectively fire only for “important” mail.

For your use case (only notify on certain high-importance mail via ntfy/Gotify), the practical route today is a trusted Sieve script at the RCPT/DATA stage using exec with curl, conditioned on whatever header/criteria defines “important.”

References:

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

If I understand correct will neither option allow different topics (API codes) for different users, so probably not really usable outside single-user setups.

I’d be interested in hearing if anyone has ideas for this?

Sieve is already per user, since each user runs their own script, and that’s where I’d do it. The server doesn’t execute http notification methods, but notify with a mailto URI works, and ntfy can publish from email. Enable its SMTP listener (smtp-server-listen, smtp-server-domain and smtp-server-addr-prefix, see Configuration - ntfy) and each user puts their own topic, plus an access token if the topic needs one, into the address:

require ["enotify"];

if anyof (header :contains "Importance" "high",
          header :matches "X-Priority" "1*",
          address :is "from" "[email protected]") {
    notify "mailto:[email protected]";
}

The original subject becomes the notification title, or add :message “…” to set your own text. Stalwart has to be able to deliver to ntfy’s SMTP listener, either through an MX record for that domain or a route to the ntfy host (Routing | Stalwart). Users can edit their scripts over ManageSieve, from Roundcube or Thunderbird’s Sieve add-on.

Webhooks are the wrong tool here: they’re server-wide telemetry, and the ingest event carries ids and a size, no subject or sender. Gotify has no email input of its own, so it would need an SMTP bridge in front of it.