# Notifications Backup admins get email about job results, problems that need attention and security-relevant activity. Email can be sent through **Microsoft Graph** (default) or **SMTP**. Settings live in the web UI under *Settings → Notifications*. ```{admonition} What is built :class: note Built: event recording; delivery every minute by the worker with minimum severity, throttling by de-duplication key, a fallback method and retries (1 min, 5 min, 15 min, 1 h, 3 h, then *failed*); Graph and SMTP senders; the Notifications app (created by *Connect tenant*, no Entra permission); *Settings → Notifications* with test buttons and the generated Exchange commands to run by hand; the *Alerts* page; Entra change alerts. Not yet: running the Exchange step automatically (`exo-runner`), daily summary and weekly report, "resolved" emails, Entra group recipients, certificate expiry and storage alerts, heartbeat. ``` ## Delivery methods ### Microsoft Graph (default) - Sends with `POST /users/{sender}/sendMail` as a dedicated **shared mailbox**, by default `backup-alerts@` (shared mailboxes need no licence). The setup wizard can **create this mailbox** for you, or use an existing one. - Uses a **separate "Mail Safehouse – Notifications" app registration** holding only `Mail.Send`. It is created by the setup wizard in the same device code step as the Backup and Restore apps ({doc}`setup`). - **Why a separate app:** the application permission `Mail.Send` lets an app send as *any* mailbox in the tenant. Keeping it off the Backup app means a leaked backup credential cannot send phishing mail as the CEO. - **Scoped to the one mailbox:** the permission is granted through Exchange *RBAC for Applications* with a management scope that matches only the sender mailbox, and **not** through an Entra admin consent. (An Entra `Mail.Send` grant is tenant-wide and would override the scope, so the wizard does not create one, and removes one if found.) - The wizard then **verifies** the scope: sending as the sender mailbox must succeed and sending as any other mailbox must be refused. #### Automated Exchange setup Creating the mailbox and the scoped role assignment needs Exchange Online PowerShell; Microsoft Graph has no API for either. The wizard runs it for you: 1. After the Graph device code sign-in, the wizard asks for a **second device code sign-in**, this time for Exchange Online (a token for Graph cannot be used for Exchange). Same admin, same `microsoft.com/devicelogin` page. 2. The `exo-runner` container (PowerShell 7 + the `ExchangeOnlineManagement` module, see {doc}`architecture`) runs a fixed, reviewed script with that token: ```powershell # Values are passed as parameters by the wizard, not string-built. New-Mailbox -Shared -Name "Backup Alerts" -Alias backup-alerts ` -PrimarySmtpAddress backup-alerts@contoso.com Set-Mailbox backup-alerts -HiddenFromAddressListsEnabled $true New-ServicePrincipal -AppId ` -ObjectId -DisplayName "Mail Safehouse – Notifications" New-ManagementScope -Name "Mail Safehouse sender" ` -RecipientRestrictionFilter "PrimarySmtpAddress -eq 'backup-alerts@contoso.com'" New-ManagementRoleAssignment -App ` -Role "Application Mail.Send" -CustomResourceScope "Mail Safehouse sender" ``` 3. The delegated Exchange token is discarded, as with Graph. Every step checks first whether its object already exists, so re-running is safe. If the admin prefers, or the `exo-runner` container is not running (it is an optional compose profile, `--profile exo`), the wizard shows the same commands to run by hand instead, then runs the verification. **Timing:** a new mailbox can take a few minutes to appear, and Exchange RBAC changes can take up to about two hours to take effect. The wizard does not block on this: it marks email as *pending*, keeps retrying the test send in the background, and shows (and emails) "notifications active" once it works. Until then, notifications are still recorded in the UI. - Sent mail is not saved to the sender's Sent Items (`saveToSentItems: false`) to avoid filling the mailbox. ### SMTP - For an external relay or mail service (Postfix, SendGrid, Mailgun, Amazon SES, an on-premises relay) or when Graph sending is not wanted. - Settings: host, port, security (`STARTTLS`, implicit TLS, or none for a trusted internal relay only), optional username/password (stored encrypted), from address. - **Not intended for Exchange Online SMTP AUTH.** Microsoft is retiring basic authentication for SMTP client submission in Exchange Online; Graph is the supported way to send from Microsoft 365. ### Fallback A second method can be set as fallback (typically SMTP behind Graph). It is used when the primary fails, which matters most for exactly the alerts you need: Graph or the Notifications app's certificate failing, or a Microsoft 365 outage. ### Outside watchdog If the server itself is down, it cannot send anything. The app exposes `/healthz` and an optional outgoing heartbeat (an HTTP ping after each successful scheduled run, e.g. to Uptime Kuma or healthchecks.io), so an external monitor can alert when the heartbeats stop. ## What is sent | Event | Default severity | Default delivery | |-------------------------------------|------------------|----------------------| | Job failed | Error | Immediately | | Job finished with warnings (items skipped/failed) | Warning | Immediately | | Job succeeded | Info | In the daily summary | | Job missed its schedule / ran too long | Error | Immediately | | Daily summary (all jobs, sizes, durations, errors) | Info | Daily, 07:00 local | | Weekly report (protected objects, storage growth, retention) | Info | Weekly | | Certificate expiring (30/14/7/1 days) | Warning | Immediately | | Missing or excess Graph permissions | Warning | Immediately | | Storage below free-space threshold | Warning/Error | Immediately | | Repository integrity check failed | Error | Immediately | | Restore or export performed | Info (security) | Immediately | | Repeated failed sign-ins / new admin added | Warning (security) | Immediately | | Module events (e.g. Entra: Conditional Access policy changed) | Per module | Configurable | Modules can declare their own event types through the module contract (`event_types()`), so the Entra module can, for example, alert when a Conditional Access policy or a privileged role assignment changes between two backups. ## Recipients and routing - One or more recipient addresses for the backup admins (plain addresses, or members of an Entra group resolved at send time). - Per event type: on/off, minimum severity, immediate or summary-only. - **Throttling and de-duplication:** the same alert for the same object is sent once, then at most once per configurable interval (default 6 h), with a "resolved" email when the condition clears. - *Send test email* button for each method. ## Message format - HTML and plain-text parts from templates (Jinja2) shipped with the app; admins can override them. - Subject prefix configurable (default `[Mail Safehouse]`) plus severity, for inbox rules: `[Mail Safehouse] [ERROR] Exchange backup failed: 2 of 10 mailboxes`. - Each message links to the job or event page in the web UI. - Job failure emails can attach the job log (gzip, size-capped at 2 MB). ## Implementation notes - A `Notifier` interface with `GraphNotifier` and `SmtpNotifier` implementations; future channels (generic webhook, ntfy) implement the same interface. - Events are written to an `event` table first, then delivered by a queued job with retries, so a failed send never blocks or fails a backup job, and every notification is visible in the UI even if email delivery fails.