Skip to content

armgit / posta

Public Imported from GitHub
0

Self-hosted email delivery platform that enables applications to send emails via HTTP APIs while handling SMTP delivery, templates, storage, security, and analytics. Fully self-hostable alternative to services like SendGrid or Mailgun.

feat(notifications): granular preferences, security alerts, and redesigned email templates (#124)

Jonas Kanindab6c76a786847
diff --git a/.env.example b/.env.example
index 7ff62fc..6e5dde2 100644
--- a/.env.example
+++ b/.env.example
@@ -42,8 +42,10 @@ POSTA_METRICS_ENABLED=false
# Vue build directory (uncomment for development)
# POSTA_WEB_DIR=web/dist
-# Public URL
+# Public URL of the dashboard / instance
POSTA_WEB_URL=https://posta.example.com
+# Public API base URL (advertised in the OpenAPI "servers" list; optional if POSTA_WEB_URL is set)
+# POSTA_API_URL=https://posta.example.com
# Allowed CORS origins
POSTA_CORS_ORIGINS=*
@@ -137,4 +139,11 @@ POSTA_EMAIL_VERIFY_CACHE_TTL_HOURS=168
# How long a domain's MX lookup is cached, in hours
POSTA_EMAIL_VERIFY_MX_CACHE_TTL_HOURS=24
# Per-user hourly cap on verification requests (0 disables the limit)
-POSTA_EMAIL_VERIFY_RATE_HOURLY=1000
\ No newline at end of file
+POSTA_EMAIL_VERIFY_RATE_HOURLY=1000
+
+# Advanced
+# Allow the server to boot when the binary version is older than the version
+# recorded in the database (normally refused to prevent schema mismatches)
+POSTA_ALLOW_DOWNGRADE=false
+# Enforce hosted plan limits / quotas. Off by default.
+POSTA_PLAN_ENFORCEMENT=false
\ No newline at end of file
diff --git a/docs/docs/getting-started/configuration.md b/docs/docs/getting-started/configuration.md
index d804545..2ca1708 100644
--- a/docs/docs/getting-started/configuration.md
+++ b/docs/docs/getting-started/configuration.md
@@ -17,6 +17,7 @@ Posta is configured via environment variables. All variables are prefixed with `
| `POSTA_DEV_MODE` | `false` | Development mode — stores emails without sending |
| `POSTA_WEB_DIR` | `web/dist` | Path to the dashboard frontend build |
| `POSTA_WEB_URL` | — | Public base URL of the Posta instance |
+| `POSTA_API_URL` | — | Public API base URL advertised in the OpenAPI `servers` list (optional if `POSTA_WEB_URL` is set) |
## Database (PostgreSQL)
@@ -45,15 +46,20 @@ Posta is configured via environment variables. All variables are prefixed with `
| `POSTA_ADMIN_EMAIL` | `[email protected]` | Initial admin account email |
| `POSTA_ADMIN_PASSWORD` | `admin1234` | Initial admin account password |
| `POSTA_CORS_ORIGINS` | `*` | Comma-separated allowed CORS origins |
+| `POSTA_ENCRYPTION_KEY` | — | AES-256-GCM key used to encrypt stored SMTP passwords. Falls back to base64 encoding only when empty. |
+| `POSTA_EMAIL_VERIFICATION_REQUIRED` | `false` | Require new users to confirm their email address before they can sign in |
## Features
| Variable | Default | Description |
|----------|---------|-------------|
-| `POSTA_REGISTRATION_ENABLED` | `true` | Allow new user registration |
| `POSTA_OPENAPI_DOCS` | `true` | Enable Swagger/ReDoc API documentation |
| `POSTA_METRICS_ENABLED` | `false` | Enable Prometheus metrics endpoint |
+:::note
+New-user registration is toggled at runtime from **Admin → Settings** (the `registration_enabled` setting), not via an environment variable.
+:::
+
## Rate Limiting
| Variable | Default | Description |
@@ -76,6 +82,85 @@ Posta is configured via environment variables. All variables are prefixed with `
|----------|---------|-------------|
| `POSTA_WEBHOOK_MAX_RETRIES` | `3` | Maximum webhook delivery retries |
| `POSTA_WEBHOOK_TIMEOUT_SECS` | `10` | Webhook HTTP request timeout (seconds) |
+| `POSTA_WEBHOOK_PROXY_URL` | — | Optional HTTP/HTTPS/SOCKS5 proxy for outbound webhook delivery |
+
+## Delivery
+
+| Variable | Default | Description |
+|----------|---------|-------------|
+| `POSTA_AUTO_SUPPRESS_ON_REJECT` | `true` | Add a recipient to the suppression list (and stop retrying) after a permanent `5xx` rejection at `RCPT TO`, e.g. `550 user unknown` |
+
+## Email Verification
+
+Controls the `POST /api/v1/emails/verify` endpoint (syntax, MX, disposable & role-account checks). Results are cached in Redis.
+
+| Variable | Default | Description |
+|----------|---------|-------------|
+| `POSTA_EMAIL_VERIFY_ENABLED` | `true` | Enable the email verification endpoint |
+| `POSTA_EMAIL_VERIFY_CACHE_TTL_HOURS` | `168` | How long an address-level result is cached, in hours (default 7 days) |
+| `POSTA_EMAIL_VERIFY_MX_CACHE_TTL_HOURS` | `24` | How long a domain's MX lookup is cached, in hours |
+| `POSTA_EMAIL_VERIFY_RATE_HOURLY` | `1000` | Per-user hourly cap on verification requests (`0` disables the limit) |
+
+## OAuth / SSO
+
+| Variable | Default | Description |
+|----------|---------|-------------|
+| `POSTA_GOOGLE_OAUTH_CLIENT_ID` | — | Google OAuth client ID for SSO login |
+| `POSTA_GOOGLE_OAUTH_CLIENT_SECRET` | — | Google OAuth client secret |
+| `POSTA_OAUTH_CALLBACK_URL` | — | OAuth callback base URL (optional if `POSTA_WEB_URL` is set) |
+
+## System SMTP
+
+Outbound SMTP server used for platform notifications (daily reports, invitations, alerts). `HOST` and `FROM` must both be set for it to activate.
+
+| Variable | Default | Description |
+|----------|---------|-------------|
+| `POSTA_SYSTEM_SMTP_HOST` | — | SMTP server host |
+| `POSTA_SYSTEM_SMTP_PORT` | `587` | SMTP server port |
+| `POSTA_SYSTEM_SMTP_USERNAME` | — | SMTP username |
+| `POSTA_SYSTEM_SMTP_PASSWORD` | — | SMTP password |
+| `POSTA_SYSTEM_SMTP_FROM` | — | From address for platform notifications |
+| `POSTA_SYSTEM_SMTP_ENCRYPTION` | `starttls` | Encryption mode: `none`, `ssl`, or `starttls` |
+
+## Blob Storage
+
+Where email attachments are stored. Leave `POSTA_BLOB_PROVIDER` empty to disable external attachment storage.
+
+| Variable | Default | Description |
+|----------|---------|-------------|
+| `POSTA_BLOB_PROVIDER` | — | Storage backend: `s3` or `filesystem` |
+| `POSTA_BLOB_S3_ENDPOINT` | — | S3-compatible endpoint (e.g. MinIO, R2) |
+| `POSTA_BLOB_S3_REGION` | `us-east-1` | S3 region |
+| `POSTA_BLOB_S3_BUCKET` | — | S3 bucket name |
+| `POSTA_BLOB_S3_ACCESS_KEY` | — | S3 access key |
+| `POSTA_BLOB_S3_SECRET_KEY` | — | S3 secret key |
+| `POSTA_BLOB_S3_USE_SSL` | `true` | Connect to S3 over TLS |
+| `POSTA_BLOB_S3_PATH_STYLE` | `false` | Use path-style addressing (required by some MinIO setups) |
+| `POSTA_BLOB_FS_PATH` | `data/attachments` | Storage path when using the `filesystem` provider |
+
+## Inbound Email
+
+| Variable | Default | Description |
+|----------|---------|-------------|
+| `POSTA_INBOUND_ENABLED` | `false` | Master toggle — enables the SMTP receiver and the `/api/v1/inbound/*` routes |
+| `POSTA_INBOUND_SMTP_HOST` | `0.0.0.0` | Bind address for the built-in SMTP receiver |
+| `POSTA_INBOUND_SMTP_PORT` | `2525` | SMTP listener port (use `25` publicly) |
+| `POSTA_INBOUND_HOSTNAME` | `posta.local` | Hostname announced in EHLO / used as TLS SNI — should match the MX record |
+| `POSTA_INBOUND_MAX_MESSAGE_SIZE` | `26214400` | Max raw message size in bytes (default 25 MiB) |
+| `POSTA_INBOUND_MAX_ATTACH_SIZE` | `10485760` | Max per-attachment size in bytes (default 10 MiB) |
+| `POSTA_INBOUND_WEBHOOK_SECRET` | — | Shared secret for the MX-provider webhook at `POST /api/v1/inbound/webhook` (sent via `X-Posta-Inbound-Secret`) |
+| `POSTA_INBOUND_TLS_MODE` | `none` | SMTP TLS mode: `none` or `starttls` |
+| `POSTA_INBOUND_TLS_CERT_FILE` | — | PEM cert path (required when TLS mode is `starttls`) |
+| `POSTA_INBOUND_TLS_KEY_FILE` | — | PEM key path (required when TLS mode is `starttls`) |
+| `POSTA_INBOUND_SMTP_RATE_LIMIT` | `60` | Per-IP max SMTP sessions per window (`0` disables) |
+| `POSTA_INBOUND_SMTP_RATE_WINDOW` | `60` | Rate-limit window in seconds |
+
+## Advanced
+
+| Variable | Default | Description |
+|----------|---------|-------------|
+| `POSTA_ALLOW_DOWNGRADE` | `false` | Allow the server to boot when the binary version is older than the version recorded in the database |
+| `POSTA_PLAN_ENFORCEMENT` | `false` | Enforce hosted plan limits / quotas |
## Example `.env` File
@@ -101,7 +186,6 @@ POSTA_ADMIN_PASSWORD=strong-admin-password
POSTA_CORS_ORIGINS=https://dashboard.yourdomain.com
# Features
-POSTA_REGISTRATION_ENABLED=false
POSTA_METRICS_ENABLED=true
# Rate Limiting
diff --git a/docs/src/pages/index.module.css b/docs/src/pages/index.module.css
index 9f71a5d..5418a58 100644
--- a/docs/src/pages/index.module.css
+++ b/docs/src/pages/index.module.css
@@ -1,23 +1,307 @@
/**
- * CSS files with the .module.css suffix will be treated as CSS modules
- * and scoped locally.
+ * Homepage styles. Scoped locally via CSS modules.
+ * Colors derive from the Infima --ifm-color-primary palette so light/dark
+ * themes stay in sync with the rest of the docs.
*/
-.heroBanner {
- padding: 4rem 0;
- text-align: center;
+/* ---------- Hero ---------- */
+
+.hero {
position: relative;
overflow: hidden;
+ padding: 6rem 0 4rem;
+ text-align: center;
+ background:
+ radial-gradient(1200px 600px at 50% -10%, rgba(124, 58, 237, 0.12), transparent 70%),
+ linear-gradient(180deg, var(--ifm-background-surface-color) 0%, var(--ifm-background-color) 100%);
+ border-bottom: 1px solid var(--ifm-toc-border-color);
}
-@media screen and (max-width: 996px) {
- .heroBanner {
- padding: 2rem;
- }
+.heroGlow {
+ position: absolute;
+ top: -200px;
+ right: -120px;
+ width: 520px;
+ height: 520px;
+ border-radius: 50%;
+ background: rgba(124, 58, 237, 0.14);
+ filter: blur(120px);
+ pointer-events: none;
+}
+
+.heroInner {
+ position: relative;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+}
+
+.badge {
+ display: inline-flex;
+ align-items: center;
+ gap: 0.5rem;
+ padding: 0.4rem 0.9rem;
+ border-radius: 999px;
+ font-size: 0.85rem;
+ font-weight: 600;
+ color: var(--ifm-color-primary-darker);
+ background: rgba(124, 58, 237, 0.1);
+ border: 1px solid rgba(124, 58, 237, 0.2);
+ margin-bottom: 1.75rem;
+}
+
+[data-theme='dark'] .badge {
+ color: var(--ifm-color-primary-lightest);
+ background: rgba(167, 139, 250, 0.12);
+ border-color: rgba(167, 139, 250, 0.25);
+}
+
+.badgeDot {
+ width: 8px;
+ height: 8px;
+ border-radius: 50%;
+ background: var(--ifm-color-primary);
+ box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.18);
+}
+
+.heroTitle {
+ font-size: clamp(2.4rem, 5vw, 4rem);
+ line-height: 1.08;
+ font-weight: 800;
+ letter-spacing: -0.02em;
+ margin-bottom: 1.25rem;
+ max-width: 18ch;
+}
+
+.gradientText {
+ background: linear-gradient(120deg, var(--ifm-color-primary) 0%, var(--ifm-color-primary-light) 100%);
+ -webkit-background-clip: text;
+ background-clip: text;
+ -webkit-text-fill-color: transparent;
+ color: transparent;
+}
+
+.heroSubtitle {
+ font-size: clamp(1.05rem, 2vw, 1.3rem);
+ line-height: 1.6;
+ color: var(--ifm-color-emphasis-700);
+ max-width: 42rem;
+ margin-bottom: 2.25rem;
}
.buttons {
display: flex;
+ flex-wrap: wrap;
align-items: center;
justify-content: center;
+ gap: 0.85rem;
+}
+
+.githubButton {
+ display: inline-flex;
+ align-items: center;
+ gap: 0.5rem;
+}
+
+.githubIcon {
+ flex-shrink: 0;
+}
+
+/* ---------- Stats ---------- */
+
+.stats {
+ display: grid;
+ grid-template-columns: repeat(4, minmax(0, 1fr));
+ gap: 1.5rem;
+ width: 100%;
+ max-width: 40rem;
+ margin-top: 3.5rem;
+}
+
+.statItem {
+ text-align: center;
+}
+
+.statValue {
+ font-size: 1.35rem;
+ font-weight: 800;
+ letter-spacing: -0.01em;
+ color: var(--ifm-heading-color);
+}
+
+.statLabel {
+ font-size: 0.85rem;
+ color: var(--ifm-color-emphasis-600);
+ margin-top: 0.2rem;
+}
+
+/* ---------- Sections ---------- */
+
+.section {
+ padding: 4.5rem 0;
+}
+
+.sectionMuted {
+ background: var(--ifm-background-surface-color);
+ border-top: 1px solid var(--ifm-toc-border-color);
+ border-bottom: 1px solid var(--ifm-toc-border-color);
+}
+
+.sectionHeader {
+ text-align: center;
+ max-width: 44rem;
+ margin: 0 auto 3rem;
+}
+
+.eyebrow {
+ font-size: 0.8rem;
+ font-weight: 700;
+ text-transform: uppercase;
+ letter-spacing: 0.08em;
+ color: var(--ifm-color-primary);
+ margin-bottom: 0.6rem;
+}
+
+.sectionTitle {
+ font-size: clamp(1.8rem, 3.5vw, 2.6rem);
+ font-weight: 800;
+ letter-spacing: -0.02em;
+ margin-bottom: 1rem;
+}
+
+.sectionLead {
+ font-size: 1.1rem;
+ line-height: 1.6;
+ color: var(--ifm-color-emphasis-700);
+ margin: 0;
+}
+
+/* ---------- Quick start ---------- */
+
+.codeColumns {
+ display: grid;
+ grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
+ gap: 1.25rem;
+ align-items: start;
+}
+
+.codeColumns :global(.theme-code-block) {
+ margin-bottom: 0;
+}
+
+.codeCta {
+ text-align: center;
+ margin-top: 1.75rem;
+ font-weight: 600;
+}
+
+/* ---------- Feature grid ---------- */
+
+.featureGrid {
+ display: grid;
+ grid-template-columns: repeat(3, minmax(0, 1fr));
+ gap: 1.25rem;
+}
+
+.card {
+ position: relative;
+ display: block;
+ padding: 1.6rem;
+ border-radius: 14px;
+ background: var(--ifm-background-color);
+ border: 1px solid var(--ifm-toc-border-color);
+ transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
+ color: inherit;
+}
+
+.card:hover {
+ transform: translateY(-4px);
+ border-color: var(--ifm-color-primary);
+ box-shadow: 0 16px 40px rgba(16, 24, 40, 0.12);
+ text-decoration: none;
+ color: inherit;
+}
+
+.cardTitle {
+ font-size: 1.15rem;
+ font-weight: 700;
+ margin-bottom: 0.5rem;
+ padding-right: 1.5rem;
+}
+
+.cardDescription {
+ font-size: 0.95rem;
+ line-height: 1.55;
+ color: var(--ifm-color-emphasis-700);
+ margin: 0;
+}
+
+.cardArrow {
+ position: absolute;
+ top: 1.6rem;
+ right: 1.6rem;
+ font-size: 1.1rem;
+ color: var(--ifm-color-primary);
+ opacity: 0;
+ transform: translateX(-6px);
+ transition: opacity 0.18s ease, transform 0.18s ease;
+}
+
+.card:hover .cardArrow {
+ opacity: 1;
+ transform: translateX(0);
+}
+
+/* ---------- Call to action ---------- */
+
+.cta {
+ text-align: center;
+ max-width: 46rem;
+ margin: 0 auto;
+ padding: 3.5rem 2rem;
+ border-radius: 20px;
+ background:
+ radial-gradient(800px 400px at 50% 0%, rgba(124, 58, 237, 0.14), transparent 70%),
+ var(--ifm-background-surface-color);
+ border: 1px solid var(--ifm-toc-border-color);
+}
+
+.ctaTitle {
+ font-size: clamp(1.6rem, 3vw, 2.2rem);
+ font-weight: 800;
+ letter-spacing: -0.02em;
+ margin-bottom: 0.75rem;
+}
+
+.ctaLead {
+ font-size: 1.1rem;
+ color: var(--ifm-color-emphasis-700);
+ margin-bottom: 1.75rem;
+}
+
+/* ---------- Responsive ---------- */
+
+@media screen and (max-width: 996px) {
+ .hero {
+ padding: 4.5rem 0 3rem;
+ }
+
+ .codeColumns {
+ grid-template-columns: 1fr;
+ }
+
+ .featureGrid {
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ }
+
+ .stats {
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ gap: 1.25rem 1rem;
+ }
+}
+
+@media screen and (max-width: 600px) {
+ .featureGrid {
+ grid-template-columns: 1fr;
+ }
}
diff --git a/docs/src/pages/index.tsx b/docs/src/pages/index.tsx
index c6ad645..54a5482 100644
--- a/docs/src/pages/index.tsx
+++ b/docs/src/pages/index.tsx
@@ -4,85 +4,252 @@ import Link from '@docusaurus/Link';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import Layout from '@theme/Layout';
import Heading from '@theme/Heading';
+import CodeBlock from '@theme/CodeBlock';
import styles from './index.module.css';
+const GITHUB_URL = 'https://github.com/goposta/posta';
+
+const SEND_EXAMPLE = `curl -X POST https://posta.example.com/api/v1/emails/send \\
+ -H "Authorization: Bearer YOUR_API_KEY" \\
+ -H "Content-Type: application/json" \\
+ -d '{
+ "from": "Acme <[email protected]>",
+ "subject": "Hello from Posta",
+ "html": "<h1>Hello!</h1>"
+ }'`;
+
+const SEND_RESPONSE = `{
+ "id": "0ae4b04e-5c64-4b2f-bad6-460f8d5d98b3",
+ "status": "queued"
+}`;
+
function HomepageHeader() {
- const {siteConfig} = useDocusaurusContext();
return (
- <header className={clsx('hero hero--primary', styles.heroBanner)}>
- <div className="container">
- <Heading as="h1" className="hero__title">
- {siteConfig.title}
+ <header className={styles.hero}>
+ <div className={styles.heroGlow} aria-hidden="true" />
+ <div className={clsx('container', styles.heroInner)}>
+ <span className={styles.badge}>
+ <span className={styles.badgeDot} aria-hidden="true" />
+ Open Source &amp; Self-Hosted
+ </span>
+
+ <Heading as="h1" className={styles.heroTitle}>
+ Self-Hosted{' '}
+ <span className={styles.gradientText}>Email Delivery</span> Platform
</Heading>
- <p className="hero__subtitle">{siteConfig.tagline}</p>
+
+ <p className={styles.heroSubtitle}>
+ Send and receive emails through a simple HTTP API. Posta handles SMTP
+ delivery, inbound mail, templates, campaigns, tracking, webhooks, and
+ security — on your own infrastructure.
+ </p>
+
<div className={styles.buttons}>
<Link
- className="button button--secondary button--lg"
+ className="button button--primary button--lg"
to="/docs/getting-started/introduction">
Get Started
</Link>
<Link
- className="button button--secondary button--outline button--lg"
- style={{marginLeft: '1rem'}}
- href="https://app.goposta.dev/docs">
- API Reference
+ className="button button--secondary button--lg"
+ to="/docs/getting-started/quickstart">
+ Quick Start
+ </Link>
+ <Link
+ className={clsx('button button--secondary button--outline button--lg', styles.githubButton)}
+ href={GITHUB_URL}>
+ <svg className={styles.githubIcon} width="20" height="20" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
+ <path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" />
+ </svg>
+ GitHub
</Link>
</div>
+
+ <div className={styles.stats}>
+ {[
+ {value: 'API-First', label: 'Architecture'},
+ {value: '3 SDKs', label: 'Go · PHP · Java'},
+ {value: 'In & Outbound', label: 'SMTP Delivery'},
+ {value: 'GDPR', label: 'Compliant'},
+ ].map((stat) => (
+ <div key={stat.value} className={styles.statItem}>
+ <div className={styles.statValue}>{stat.value}</div>
+ <div className={styles.statLabel}>{stat.label}</div>
+ </div>
+ ))}
+ </div>
</div>
</header>
);
}
+function QuickStart() {
+ return (
+ <section className={styles.section}>
+ <div className="container">
+ <div className={styles.sectionHeader}>
+ <p className={styles.eyebrow}>Simple API</p>
+ <Heading as="h2" className={styles.sectionTitle}>
+ Send your first email in seconds
+ </Heading>
+ <p className={styles.sectionLead}>
+ A single HTTP request is all you need. Posta handles queuing, SMTP
+ delivery, retries, and tracking automatically.
+ </p>
+ </div>
+
+ <div className={styles.codeColumns}>
+ <CodeBlock language="bash" title="Send an email">
+ {SEND_EXAMPLE}
+ </CodeBlock>
+ <CodeBlock language="json" title="Response">
+ {SEND_RESPONSE}
+ </CodeBlock>
+ </div>
+
+ <div className={styles.codeCta}>
+ <Link to="/docs/getting-started/quickstart">
+ Read the full quickstart guide →
+ </Link>
+ </div>
+ </div>
+ </section>
+ );
+}
+
type FeatureItem = {
title: string;
- description: ReactNode;
+ description: string;
link: string;
};
-const FeatureList: FeatureItem[] = [
+const FEATURES: FeatureItem[] = [
{
title: 'Email Delivery',
- description: 'Send single, template, and batch emails via REST API with attachments, scheduling, and delivery tracking.',
+ description: 'REST API for transactional, batch, and templated sends with attachments, scheduling, retries, and priority queues.',
link: '/docs/email-sending/single-email',
},
+ {
+ title: 'Inbound Email',
+ description: 'Built-in SMTP receiver with TLS plus HMAC webhook ingest, attachment storage, forwarding, and a real-time SSE stream.',
+ link: '/docs/inbound/overview',
+ },
{
title: 'Templates & Localization',
- description: 'Version-controlled templates with multi-language support, variable substitution, and CSS inlining.',
+ description: 'Version-controlled templates with multi-language fallback, variable substitution, and CSS inlining.',
link: '/docs/templates/overview',
},
{
- title: 'SMTP & Domain Management',
- description: 'Configure multiple SMTP servers and verify domains with SPF, DKIM, and DMARC.',
+ title: 'Campaigns',
+ description: 'Bulk sending with subscriber targeting, timezone-aware scheduling, A/B testing, and send-rate throttling.',
+ link: '/docs/campaigns/overview',
+ },
+ {
+ title: 'SMTP & Domains',
+ description: 'Configure multiple SMTP providers, share pools across teams, and verify domains with SPF, DKIM, and DMARC.',
link: '/docs/smtp-domains/smtp-servers',
},
{
title: 'Security',
- description: 'API keys with IP allowlists, JWT auth, two-factor authentication, and rate limiting.',
+ description: 'API keys with IP allowlists, JWT auth, two-factor authentication, OAuth/SSO, and rate limiting.',
link: '/docs/security/authentication',
},
+ {
+ title: 'Contacts & Subscribers',
+ description: 'Auto-tracked contacts, static and dynamic lists, bulk CSV/JSON import, and automatic suppression handling.',
+ link: '/docs/subscribers/subscriber-management',
+ },
+ {
+ title: 'Tracking & Analytics',
+ description: 'Pixel-based open and click tracking, per-email engagement metrics, Prometheus integration, and dashboards.',
+ link: '/docs/tracking/overview',
+ },
{
title: 'Webhooks & Events',
- description: 'Real-time notifications on email events with HMAC signature verification and retry logic.',
+ description: 'Event-driven delivery with HMAC signatures, retry strategies, delivery tracking, and audit logs.',
link: '/docs/webhooks/overview',
},
+ {
+ title: 'Workspaces & RBAC',
+ description: 'Multi-tenant isolated workspaces with role-based access, member invitations, and workspace-scoped API keys.',
+ link: '/docs/workspaces/overview',
+ },
{
title: 'Official SDKs',
description: 'Client libraries for Go, PHP, and Java with typed errors and full API coverage.',
link: '/docs/sdks/overview',
},
+ {
+ title: 'GDPR & Compliance',
+ description: 'Per-contact data export, import, and deletion tools to keep your sending compliant.',
+ link: '/docs/gdpr/data-export-import',
+ },
];
function Feature({title, description, link}: FeatureItem) {
return (
- <div className={clsx('col col--4')} style={{marginBottom: '2rem'}}>
- <div className="padding-horiz--md">
- <Heading as="h3">
- <Link to={link}>{title}</Link>
- </Heading>
- <p>{description}</p>
+ <Link to={link} className={styles.card}>
+ <Heading as="h3" className={styles.cardTitle}>{title}</Heading>
+ <p className={styles.cardDescription}>{description}</p>
+ <span className={styles.cardArrow} aria-hidden="true">→</span>
+ </Link>
+ );
+}
+
+function Features() {
+ return (
+ <section className={clsx(styles.section, styles.sectionMuted)}>
+ <div className="container">
+ <div className={styles.sectionHeader}>
+ <p className={styles.eyebrow}>Features</p>
+ <Heading as="h2" className={styles.sectionTitle}>
+ Everything you need to deliver email
+ </Heading>
+ <p className={styles.sectionLead}>
+ A complete email infrastructure platform — outbound and inbound
+ delivery, templates, campaigns, contacts, tracking, webhooks,
+ workspaces, security, and a built-in dashboard.
+ </p>
+ </div>
+
+ <div className={styles.featureGrid}>
+ {FEATURES.map((feature) => (
+ <Feature key={feature.title} {...feature} />
+ ))}
+ </div>
+ </div>
+ </section>
+ );
+}
+
+function CallToAction() {
+ return (
+ <section className={styles.section}>
+ <div className="container">
+ <div className={styles.cta}>
+ <Heading as="h2" className={styles.ctaTitle}>
+ Ready to run your own email platform?
+ </Heading>
+ <p className={styles.ctaLead}>
+ Deploy Posta with Docker in minutes and send your first email today.
+ </p>
+ <div className={styles.buttons}>
+ <Link
+ className="button button--primary button--lg"
+ to="/docs/getting-started/installation">
+ Install Posta
+ </Link>
+ <Link
+ className="button button--secondary button--lg"
+ to="/docs/getting-started/quickstart">
+ Quick Start
+ </Link>
+ </div>
+ </div>
</div>
- </div>
+ </section>
);
}
@@ -91,18 +258,12 @@ export default function Home(): ReactNode {
return (
<Layout
title="Documentation"
- description="Posta - Self-hosted email delivery platform for developers">
+ description={`${siteConfig.title} — ${siteConfig.tagline}`}>
<HomepageHeader />
<main>
- <section style={{padding: '2rem 0'}}>
- <div className="container">
- <div className="row">
- {FeatureList.map((props, idx) => (
- <Feature key={idx} {...props} />
- ))}
- </div>
- </div>
- </section>
+ <QuickStart />
+ <Features />
+ <CallToAction />
</main>
</Layout>
);
diff --git a/internal/handlers/api_key_handler.go b/internal/handlers/api_key_handler.go
index 8e20987..b8966db 100644
--- a/internal/handlers/api_key_handler.go
+++ b/internal/handlers/api_key_handler.go
@@ -117,7 +117,7 @@ func (h *APIKeyHandler) Create(c *okapi.Context, req *CreateAPIKeyRequest) error
expiresStr = key.ExpiresAt.Format("January 2, 2006")
}
go func() {
- _ = h.notifier.SendToUser(scope.UserID, fmt.Sprintf("New API key created: %s", key.Name), notification.TemplateAPIKeyCreated, map[string]any{
+ _ = h.notifier.SendSecurityToUser(scope.UserID, fmt.Sprintf("New API key created: %s", key.Name), notification.TemplateAPIKeyCreated, map[string]any{
"KeyName": key.Name,
"KeyPrefix": key.KeyPrefix,
"ExpiresAt": expiresStr,
diff --git a/internal/handlers/session_handler.go b/internal/handlers/session_handler.go
index 3186cb6..48dc61b 100644
--- a/internal/handlers/session_handler.go
+++ b/internal/handlers/session_handler.go
@@ -20,6 +20,7 @@ package handlers
import (
"fmt"
+ "github.com/goposta/posta/internal/services/clientinfo"
"github.com/goposta/posta/internal/services/session"
"github.com/goposta/posta/internal/storage/repositories"
"github.com/jkaninda/okapi"
@@ -39,6 +40,10 @@ type SessionResponse struct {
ID uint `json:"id"`
IPAddress string `json:"ip_address"`
UserAgent string `json:"user_agent"`
+ Browser string `json:"browser"`
+ OS string `json:"os"`
+ Device string `json:"device"`
+ Label string `json:"label"`
Current bool `json:"current"`
CreatedAt string `json:"created_at"`
ExpiresAt string `json:"expires_at"`
@@ -60,10 +65,15 @@ func (h *SessionHandler) List(c *okapi.Context) error {
result := make([]SessionResponse, 0, len(sessions))
for _, s := range sessions {
+ client := clientinfo.Parse(s.UserAgent)
result = append(result, SessionResponse{
ID: s.ID,
IPAddress: s.IPAddress,
UserAgent: s.UserAgent,
+ Browser: client.Browser,
+ OS: client.OS,
+ Device: client.Device,
+ Label: client.Label(),
Current: s.JTI == currentJTI,
CreatedAt: s.CreatedAt.Format("2006-01-02T15:04:05Z"),
ExpiresAt: s.ExpiresAt.Format("2006-01-02T15:04:05Z"),
diff --git a/internal/handlers/tracking_handler.go b/internal/handlers/tracking_handler.go
index 648f37f..7798013 100644
--- a/internal/handlers/tracking_handler.go
+++ b/internal/handlers/tracking_handler.go
@@ -19,8 +19,8 @@ package handlers
import (
"encoding/json"
- "fmt"
"html"
+ "html/template"
"net/http"
"regexp"
"strings"
@@ -141,30 +141,27 @@ func (h *TrackingHandler) ClickRedirect(c *okapi.Context, req *TrackingClickRequ
func (h *TrackingHandler) UnsubscribePage(c *okapi.Context, req *TrackingUnsubscribeRequest) error {
messageID, err := h.trackingService.VerifyUnsubscribeToken(req.Token)
if err != nil {
- return c.HTMLView(http.StatusNotFound, "Invalid or expired unsubscribe link", okapi.M{})
+ return trackingNotice(c, http.StatusNotFound, "Link expired", "This unsubscribe link is invalid or has expired.", "error")
}
msg, err := h.messageRepo.FindByCampaignMessageID(messageID)
if err != nil {
- return c.HTMLView(http.StatusNotFound, "Message not found", okapi.M{})
-
+ return trackingNotice(c, http.StatusNotFound, "Not found", "We couldn't find the message this link points to.", "error")
}
sub, err := h.subRepo.FindByID(msg.SubscriberID)
if err != nil {
- return c.HTMLView(http.StatusNotFound, "Subscriber not found", okapi.M{})
+ return trackingNotice(c, http.StatusNotFound, "Not found", "We couldn't find the recipient for this link.", "error")
}
- html := fmt.Sprintf(`<!DOCTYPE html><html><head><meta charset="utf-8"><title>Unsubscribe</title>
-<style>body{font-family:sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;margin:0;background:#f9fafb}
-.card{background:#fff;border-radius:12px;padding:40px;max-width:420px;text-align:center;box-shadow:0 2px 8px rgba(0,0,0,0.08)}
-h1{font-size:20px;margin-bottom:8px}p{color:#6b7280;font-size:14px;margin-bottom:20px}
-button{background:#9333ea;color:#fff;border:none;padding:12px 32px;border-radius:8px;font-size:15px;cursor:pointer}
-button:hover{background:#7e22ce}.done{color:#16a34a;font-weight:600}</style></head><body>
-<div class="card"><h1>Unsubscribe</h1><p>%s</p>
-<form method="POST"><button type="submit">Confirm Unsubscribe</button></form></div></body></html>`, html.EscapeString(sub.Email))
-
- return c.HTMLView(http.StatusOK, html, okapi.M{})
+ return trackingHTMLView(c, http.StatusOK, "unsubscribe", unsubData{
+ Title: "Unsubscribe",
+ Heading: "Unsubscribe from this list?",
+ Message: "You're about to stop receiving these emails at:",
+ Recipient: sub.Email,
+ ButtonLabel: "Confirm unsubscribe",
+ Fine: "Other lists you're subscribed to won't be affected.",
+ })
}
// TxUnsubscribePage renders a confirmation page for a transactional one-click
@@ -173,26 +170,24 @@ button:hover{background:#7e22ce}.done{color:#16a34a;font-weight:600}</style></he
func (h *TrackingHandler) TxUnsubscribePage(c *okapi.Context, req *TrackingUnsubscribeRequest) error {
emailID, err := h.trackingService.VerifyTxUnsubscribeToken(req.Token)
if err != nil {
- return c.HTMLView(http.StatusNotFound, "Invalid or expired unsubscribe link", okapi.M{})
+ return trackingNotice(c, http.StatusNotFound, "Link expired", "This unsubscribe link is invalid or has expired.", "error")
}
em, err := h.emailRepo.FindByID(emailID)
if err != nil || em == nil {
- return c.HTMLView(http.StatusNotFound, "Message not found", okapi.M{})
+ return trackingNotice(c, http.StatusNotFound, "Not found", "We couldn't find the message this link points to.", "error")
}
shown := ""
if len(em.Recipients) > 0 {
shown = em.Recipients[0]
}
- page := fmt.Sprintf(`<!DOCTYPE html><html><head><meta charset="utf-8"><title>Unsubscribe</title>
-<style>body{font-family:sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;margin:0;background:#f9fafb}
-.card{background:#fff;border-radius:12px;padding:40px;max-width:420px;text-align:center;box-shadow:0 2px 8px rgba(0,0,0,0.08)}
-h1{font-size:20px;margin-bottom:8px}p{color:#6b7280;font-size:14px;margin-bottom:20px}
-button{background:#9333ea;color:#fff;border:none;padding:12px 32px;border-radius:8px;font-size:15px;cursor:pointer}
-button:hover{background:#7e22ce}</style></head><body>
-<div class="card"><h1>Unsubscribe</h1><p>%s</p>
-<form method="POST"><button type="submit">Confirm Unsubscribe</button></form></div></body></html>`, html.EscapeString(shown))
-
- return c.HTMLView(http.StatusOK, page, okapi.M{})
+ return trackingHTMLView(c, http.StatusOK, "unsubscribe", unsubData{
+ Title: "Unsubscribe",
+ Heading: "Unsubscribe from these emails?",
+ Message: "You're about to stop receiving this type of email at:",
+ Recipient: shown,
+ ButtonLabel: "Confirm unsubscribe",
+ Fine: "You'll still receive other essential messages from the sender.",
+ })
}
// TxUnsubscribeConfirm processes a POST to the transactional unsubscribe link.
@@ -201,16 +196,14 @@ button:hover{background:#7e22ce}</style></head><body>
func (h *TrackingHandler) TxUnsubscribeConfirm(c *okapi.Context, req *TrackingUnsubscribeRequest) error {
emailID, err := h.trackingService.VerifyTxUnsubscribeToken(req.Token)
if err != nil {
- return c.HTMLView(http.StatusNotFound, "Invalid or expired unsubscribe link", okapi.M{})
+ return trackingNotice(c, http.StatusNotFound, "Link expired", "This unsubscribe link is invalid or has expired.", "error")
}
em, err := h.emailRepo.FindByID(emailID)
if err != nil || em == nil {
- return c.HTMLView(http.StatusNotFound, "Message not found", okapi.M{})
+ return trackingNotice(c, http.StatusNotFound, "Not found", "We couldn't find the message this link points to.", "error")
}
if h.suppressionRepo != nil {
- // A Posta-minted link carries a list ⇒ scoped opt-out. A nil list means a
- // legacy link, which keeps the old global behavior.
kind := models.SuppressionKindHard
if em.UnsubscribeListID != nil {
kind = models.SuppressionKindListUnsubscribe
@@ -231,18 +224,10 @@ func (h *TrackingHandler) TxUnsubscribeConfirm(c *okapi.Context, req *TrackingUn
}
}
- confirmHTML := `<!DOCTYPE html><html><head><meta charset="utf-8"><title>Unsubscribed</title>
-<style>body{font-family:sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;margin:0;background:#f9fafb}
-.card{background:#fff;border-radius:12px;padding:40px;max-width:420px;text-align:center;box-shadow:0 2px 8px rgba(0,0,0,0.08)}
-h1{font-size:20px;color:#16a34a}p{color:#6b7280;font-size:14px}</style></head><body>
-<div class="card"><h1>Unsubscribed</h1><p>You will no longer receive emails of this type from the sender.</p></div></body></html>`
-
- return c.HTMLView(http.StatusOK, confirmHTML, okapi.M{})
+ return trackingNotice(c, http.StatusOK, "You're unsubscribed",
+ "You'll no longer receive emails of this type from the sender.", "success")
}
-// emitUnsubscribed fires the email.unsubscribed webhook for a one-click opt-out.
-// It uses DispatchJSON because the payload is richer than the standard outbound
-// {event, email_id} shape — it carries the recipient and the scoped list.
func (h *TrackingHandler) emitUnsubscribed(em *models.Email, addr string) {
if h.dispatcher == nil {
return
@@ -267,24 +252,20 @@ func (h *TrackingHandler) emitUnsubscribed(em *models.Email, addr string) {
h.dispatcher.DispatchJSON(em.UserID, em.WorkspaceID, "email.unsubscribed", body, em.Sender)
}
-// WebView renders a hosted copy of a sent email ("view in browser"). The token is
-// an HMAC-signed, expiring capability bound to the email's opaque UUID. Because the
-// page renders arbitrary customer HTML, it is served with a restrictive CSP, no
-// cookies, and noindex, and the open-tracking pixel is stripped so a web view does
-// not inflate open metrics.
+// WebView renders a hosted copy of a sent email ("view in browser").
func (h *TrackingHandler) WebView(c *okapi.Context, req *TrackingWebViewRequest) error {
emailUUID, err := h.trackingService.VerifyWebViewToken(req.Token)
if err != nil {
- return c.HTMLView(http.StatusNotFound, "This link is invalid or has expired.", okapi.M{})
+ return trackingNotice(c, http.StatusNotFound, "Link expired", "This link is invalid or has expired.", "error")
}
em, err := h.emailRepo.FindByUUID(emailUUID)
if err != nil || em == nil {
- return c.HTMLView(http.StatusNotFound, "Message not found", okapi.M{})
+ return trackingNotice(c, http.StatusNotFound, "Not found", "We couldn't find the message this link points to.", "error")
}
body := em.HTMLBody
if strings.TrimSpace(body) == "" {
- body = "<pre style=\"white-space:pre-wrap;font-family:sans-serif\">" + html.EscapeString(em.TextBody) + "</pre>"
+ body = "<pre style=\"white-space:pre-wrap;font-family:sans-serif;padding:24px;margin:0\">" + html.EscapeString(em.TextBody) + "</pre>"
}
body = openPixelRe.ReplaceAllString(body, "")
@@ -293,31 +274,27 @@ func (h *TrackingHandler) WebView(c *okapi.Context, req *TrackingWebViewRequest)
hdr.Set("X-Robots-Tag", "noindex, nofollow")
hdr.Set("Referrer-Policy", "no-referrer")
- page := fmt.Sprintf(`<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">
-<meta name="viewport" content="width=device-width, initial-scale=1"><meta name="robots" content="noindex, nofollow">
-<title>%s</title>
-<style>body{margin:0;background:#f3f4f6}.posta-wv-bar{font-family:sans-serif;font-size:12px;color:#6b7280;text-align:center;padding:10px;background:#fff;border-bottom:1px solid #e5e7eb}.posta-wv-body{max-width:680px;margin:0 auto;padding:16px}</style>
-</head><body><div class="posta-wv-bar">You are viewing a copy of an email.</div><div class="posta-wv-body">%s</div></body></html>`,
- html.EscapeString(em.Subject), body)
-
- return c.HTMLView(http.StatusOK, page, okapi.M{})
+ return trackingHTMLView(c, http.StatusOK, "webview", webViewData{
+ Subject: em.Subject,
+ Body: template.HTML(body),
+ })
}
// UnsubscribeConfirm processes the unsubscribe action.
func (h *TrackingHandler) UnsubscribeConfirm(c *okapi.Context, req *TrackingUnsubscribeRequest) error {
messageID, err := h.trackingService.VerifyUnsubscribeToken(req.Token)
if err != nil {
- return c.HTMLView(http.StatusNotFound, "Invalid or expired unsubscribe link", okapi.M{})
+ return trackingNotice(c, http.StatusNotFound, "Link expired", "This unsubscribe link is invalid or has expired.", "error")
}
msg, err := h.messageRepo.FindByCampaignMessageID(messageID)
if err != nil {
- return c.HTMLView(http.StatusNotFound, "Message not found", okapi.M{})
+ return trackingNotice(c, http.StatusNotFound, "Not found", "We couldn't find the message this link points to.", "error")
}
camp, err := h.campaignRepo.FindByID(msg.CampaignID)
if err != nil {
- return c.HTMLView(http.StatusNotFound, "Campaign not found", okapi.M{})
+ return trackingNotice(c, http.StatusNotFound, "Not found", "We couldn't find the campaign this link points to.", "error")
}
// Suppress this subscriber on the campaign's list
@@ -336,13 +313,8 @@ func (h *TrackingHandler) UnsubscribeConfirm(c *okapi.Context, req *TrackingUnsu
UserAgent: c.Request().UserAgent(),
})
- confirmHTML := `<!DOCTYPE html><html><head><meta charset="utf-8"><title>Unsubscribed</title>
-<style>body{font-family:sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;margin:0;background:#f9fafb}
-.card{background:#fff;border-radius:12px;padding:40px;max-width:420px;text-align:center;box-shadow:0 2px 8px rgba(0,0,0,0.08)}
-h1{font-size:20px;color:#16a34a}p{color:#6b7280;font-size:14px}</style></head><body>
-<div class="card"><h1>Unsubscribed</h1><p>You have been removed from this mailing list. Other lists you are subscribed to are unaffected.</p></div></body></html>`
-
- return c.HTMLView(http.StatusOK, confirmHTML, okapi.M{})
+ return trackingNotice(c, http.StatusOK, "You're unsubscribed",
+ "You've been removed from this mailing list. Other lists you're subscribed to are unaffected.", "success")
}
type CampaignAnalyticsRequest struct {
@@ -421,7 +393,6 @@ func (h *TrackingHandler) recordClick(messageID uint, linkID uint, ip, userAgent
// Increment link click count
h.trackingRepo.IncrementLinkClickCount(linkID)
- // Record event (unique per link per message for deduplication stats)
if !h.trackingRepo.HasClickEvent(msg.ID, linkID) {
_ = h.trackingRepo.CreateEvent(&models.TrackingEvent{
CampaignMessageID: msg.ID,
diff --git a/internal/handlers/tracking_pages.go b/internal/handlers/tracking_pages.go
new file mode 100644
index 0000000..dbdd539
--- /dev/null
+++ b/internal/handlers/tracking_pages.go
@@ -0,0 +1,180 @@
+/*
+ * Copyright 2026 Jonas Kaninda
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package handlers
+
+import (
+ "html/template"
+
+ "github.com/jkaninda/okapi"
+)
+
+type noticeData struct {
+ Title string
+ Heading string
+ Message string
+ Variant string // "brand" | "success" | "error"
+}
+
+func (n noticeData) HeadingText() string {
+ if n.Heading != "" {
+ return n.Heading
+ }
+ return n.Title
+}
+
+// unsubData drives the unsubscribe confirmation page (with the POST form).
+type unsubData struct {
+ Title string
+ Heading string
+ Recipient string
+ Message string
+ ButtonLabel string
+ Fine string
+}
+
+// webViewData drives the hosted email page.
+type webViewData struct {
+ Subject string
+ Body template.HTML
+}
+
+func trackingHTMLView(c *okapi.Context, status int, page string, data any) error {
+ return c.HTMLView(status, trackingPageTemplates+`{{template "`+page+`" .}}`, data)
+}
+
+// trackingNotice renders an error/info notice card to the response.
+func trackingNotice(c *okapi.Context, status int, title, message, variant string) error {
+ return trackingHTMLView(c, status, "notice", noticeData{
+ Title: title,
+ Message: message,
+ Variant: variant,
+ })
+}
+
+const trackingPageTemplates = `
+{{define "head"}}<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<meta name="robots" content="noindex, nofollow">
+<meta name="color-scheme" content="light dark">
+<title>{{.Title}}</title>
+<style>
+ *{box-sizing:border-box}
+ body{margin:0;min-height:100vh;display:flex;align-items:center;justify-content:center;padding:24px;
+ font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;
+ background:#eef0f5;color:#374151;line-height:1.6;-webkit-font-smoothing:antialiased}
+ .card{background:#fff;border-radius:16px;padding:44px 36px;max-width:460px;width:100%;text-align:center;
+ box-shadow:0 1px 2px rgba(16,24,40,.04),0 10px 28px rgba(16,24,40,.08)}
+ .badge{display:inline-flex;align-items:center;justify-content:center;width:60px;height:60px;border-radius:16px;margin-bottom:22px}
+ .badge svg{width:30px;height:30px}
+ .badge-brand{background:#f3e8ff;color:#7c3aed}
+ .badge-success{background:#dcfce7;color:#16a34a}
+ .badge-error{background:#fee2e2;color:#dc2626}
+ h1{font-size:22px;font-weight:700;color:#111827;margin:0 0 10px;letter-spacing:-.01em}
+ p{font-size:15px;color:#6b7280;margin:0 0 6px}
+ .recipient{display:inline-block;margin:4px 0 4px;font-weight:600;color:#111827;
+ background:#f3f4f6;border-radius:8px;padding:6px 12px;font-size:14px;word-break:break-all}
+ form{margin:26px 0 4px}
+ .btn{display:inline-block;border:none;cursor:pointer;font-size:15px;font-weight:600;
+ padding:13px 32px;border-radius:10px;text-decoration:none;transition:background .15s}
+ .btn-primary{background:#7c3aed;color:#fff}
+ .btn-primary:hover{background:#6d28d9}
+ .fine{font-size:13px;color:#9ca3af;margin-top:16px}
+ @media (prefers-color-scheme:dark){
+ body{background:#0f1115;color:#cbd2dd}
+ .card{background:#1a1d24;box-shadow:none}
+ h1{color:#f3f4f6}
+ .recipient{background:#2a2e38;color:#f3f4f6}
+ }
+</style>
+</head>
+{{end}}
+
+{{define "icon"}}
+{{if eq . "success"}}<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></svg>
+{{else if eq . "error"}}<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 8v4.5M12 16h.01"/></svg>
+{{else}}<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3.5 7 8.5 6 8.5-6"/></svg>{{end}}
+{{end}}
+
+{{define "notice"}}{{template "head" .}}
+<body>
+ <div class="card">
+ <div class="badge badge-{{if .Variant}}{{.Variant}}{{else}}brand{{end}}">{{template "icon" .Variant}}</div>
+ <h1>{{.HeadingText}}</h1>
+ {{if .Message}}<p>{{.Message}}</p>{{end}}
+ </div>
+</body>
+</html>{{end}}
+
+{{define "unsubscribe"}}{{template "head" .}}
+<body>
+ <div class="card">
+ <div class="badge badge-brand">{{template "icon" "brand"}}</div>
+ <h1>{{.Heading}}</h1>
+ {{if .Message}}<p>{{.Message}}</p>{{end}}
+ {{if .Recipient}}<span class="recipient">{{.Recipient}}</span>{{end}}
+ <form method="POST">
+ <button type="submit" class="btn btn-primary">{{.ButtonLabel}}</button>
+ </form>
+ {{if .Fine}}<p class="fine">{{.Fine}}</p>{{end}}
+ </div>
+</body>
+</html>{{end}}
+
+{{define "webview"}}<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<meta name="robots" content="noindex, nofollow">
+<title>{{.Subject}}</title>
+<style>
+ body{margin:0;background:#eef0f5;color:#374151;
+ font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif}
+ .wv-bar{position:sticky;top:0;z-index:10;display:flex;align-items:center;gap:12px;
+ padding:12px 18px;background:#fff;border-bottom:1px solid #e5e7eb;box-shadow:0 1px 2px rgba(16,24,40,.04)}
+ .wv-mark{flex:none;width:34px;height:34px;border-radius:9px;background:#7c3aed;color:#fff;
+ display:flex;align-items:center;justify-content:center}
+ .wv-mark svg{width:18px;height:18px}
+ .wv-meta{min-width:0}
+ .wv-label{font-size:11px;text-transform:uppercase;letter-spacing:.06em;color:#9ca3af;font-weight:600}
+ .wv-subject{font-size:14px;font-weight:600;color:#111827;
+ white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:60vw}
+ .wv-wrap{max-width:720px;margin:24px auto;padding:0 16px}
+ .wv-sheet{background:#fff;border:1px solid #e5e7eb;border-radius:14px;overflow:hidden;
+ box-shadow:0 1px 2px rgba(16,24,40,.04),0 8px 24px rgba(16,24,40,.06)}
+ .wv-footer{text-align:center;font-size:12px;color:#9ca3af;padding:18px 16px 28px}
+</style>
+</head>
+<body>
+ <div class="wv-bar">
+ <div class="wv-mark"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3.5 7 8.5 6 8.5-6"/></svg></div>
+ <div class="wv-meta">
+ <div class="wv-label">Viewing in browser</div>
+ <div class="wv-subject">{{.Subject}}</div>
+ </div>
+ </div>
+ <div class="wv-wrap">
+ <div class="wv-sheet">{{.Body}}</div>
+ </div>
+ <div class="wv-footer">This is a web copy of an email you received.</div>
+</body>
+</html>{{end}}
+`
diff --git a/internal/handlers/user_handler.go b/internal/handlers/user_handler.go
index 987b24f..e2821e5 100644
--- a/internal/handlers/user_handler.go
+++ b/internal/handlers/user_handler.go
@@ -27,6 +27,7 @@ import (
"github.com/google/uuid"
"github.com/goposta/posta/internal/dto"
"github.com/goposta/posta/internal/models"
+ "github.com/goposta/posta/internal/services/clientinfo"
"github.com/goposta/posta/internal/services/emailverify"
"github.com/goposta/posta/internal/services/eventbus"
"github.com/goposta/posta/internal/services/notification"
@@ -356,7 +357,7 @@ func (h *UserHandler) ChangePassword(c *okapi.Context, req *ChangePasswordReques
// Send password change notification (best-effort)
if h.notifier != nil {
go func() {
- _ = h.notifier.SendToUser(user.ID, "Your password has been changed", notification.TemplatePasswordChanged, map[string]any{
+ _ = h.notifier.SendSecurityToUser(user.ID, "Your password has been changed", notification.TemplatePasswordChanged, map[string]any{
"ChangedAt": time.Now().UTC().Format("January 2, 2006 at 15:04 UTC"),
})
}()
@@ -420,12 +421,21 @@ func (h *UserHandler) Login(c *okapi.Context, req *LoginRequest) error {
fmt.Sprintf("User %q logged in", user.Email), nil)
}
+ // Detect a sign-in from a new device before the session is recorded, so the
+ // freshly created session doesn't count as a prior known device.
+ ua := c.Header("User-Agent")
+ newDevice := h.isNewDevice(user.ID, ua)
+
token, jti, err := h.generateTokenWithSession(c, user)
if err != nil {
return c.AbortInternalServerError("failed to generate token", err)
}
_ = jti
+ if newDevice {
+ h.sendLoginAlert(user.ID, ua, c.RealIP())
+ }
+
return ok(c, AuthResponse{
Token: token,
User: struct {
@@ -515,6 +525,8 @@ func (h *UserHandler) Verify2FA(c *okapi.Context, req *Verify2FARequest) error {
return c.AbortInternalServerError("failed to enable 2FA")
}
+ h.sendTwoFactorAlert(user.ID, "enabled")
+
return ok(c, okapi.M{"message": "2FA enabled successfully"})
}
@@ -539,9 +551,62 @@ func (h *UserHandler) Disable2FA(c *okapi.Context, req *Disable2FARequest) error
return c.AbortInternalServerError("failed to disable 2FA")
}
+ h.sendTwoFactorAlert(user.ID, "disabled")
+
return ok(c, okapi.M{"message": "2FA disabled successfully"})
}
+func (h *UserHandler) isNewDevice(userID uint, ua string) bool {
+ if h.sessionRepo == nil {
+ return false
+ }
+ sessions, err := h.sessionRepo.FindActiveByUserID(userID)
+ if err != nil {
+ return false
+ }
+ sig := clientinfo.Parse(ua).Signature()
+ for _, s := range sessions {
+ if clientinfo.Parse(s.UserAgent).Signature() == sig {
+ return false
+ }
+ }
+ return true
+}
+
+// sendLoginAlert emails the user about a sign-in from a new device (best-effort).
+func (h *UserHandler) sendLoginAlert(userID uint, ua, ip string) {
+ if h.notifier == nil {
+ return
+ }
+ client := clientinfo.Parse(ua)
+ data := map[string]any{
+ "Browser": client.Browser,
+ "OS": client.OS,
+ "Device": client.Device,
+ "IPAddress": ip,
+ "LoginAt": time.Now().UTC().Format("January 2, 2006 at 15:04 UTC"),
+ }
+ go func() {
+ _ = h.notifier.SendSecurityToUser(userID, "New sign-in to your account", notification.TemplateLoginAlert, data)
+ }()
+}
+
+// sendTwoFactorAlert emails the user when 2FA is enabled or disabled (best-effort).
+// action must be "enabled" or "disabled".
+func (h *UserHandler) sendTwoFactorAlert(userID uint, action string) {
+ if h.notifier == nil {
+ return
+ }
+ subject := "Two-factor authentication " + action
+ data := map[string]any{
+ "Action": action,
+ "ChangedAt": time.Now().UTC().Format("January 2, 2006 at 15:04 UTC"),
+ }
+ go func() {
+ _ = h.notifier.SendSecurityToUser(userID, subject, notification.TemplateTwoFactorChange, data)
+ }()
+}
+
// generateTokenWithSession creates a JWT with a jti claim and records the session.
func (h *UserHandler) generateTokenWithSession(c *okapi.Context, user *models.User) (string, string, error) { //nolint:unparam
jti := uuid.NewString()
@@ -606,6 +671,17 @@ func (h *UserHandler) RequestAccountDeletion(c *okapi.Context) error {
fmt.Sprintf("Account deletion scheduled for %s", deletionDate.Format("2006-01-02")), nil)
}
+ // Confirm the scheduled deletion by email (best-effort).
+ if h.notifier != nil {
+ uid := user.ID
+ data := map[string]any{
+ "ScheduledFor": deletionDate.UTC().Format("January 2, 2006"),
+ }
+ go func() {
+ _ = h.notifier.SendSecurityToUser(uid, "Your account is scheduled for deletion", notification.TemplateAccountDeletion, data)
+ }()
+ }
+
return ok(c, map[string]any{
"message": "Account scheduled for deletion",
"scheduled_deletion_at": deletionDate,
diff --git a/internal/handlers/user_setting_handler.go b/internal/handlers/user_setting_handler.go
index 944bd16..e07ce78 100644
--- a/internal/handlers/user_setting_handler.go
+++ b/internal/handlers/user_setting_handler.go
@@ -44,6 +44,10 @@ type UpdateUserSettingsRequest struct {
BounceAutoSuppress *bool `json:"bounce_auto_suppress"`
DefaultLanguage *string `json:"default_language"`
DailyReport *bool `json:"daily_report"`
+
+ NotifyBounceAlerts *bool `json:"notify_bounce_alerts"`
+ NotifyAPIKeyExpiry *bool `json:"notify_api_key_expiry"`
+ NotifyWorkspaceActivity *bool `json:"notify_workspace_activity"`
} `json:"body"`
}
@@ -98,6 +102,15 @@ func (h *UserSettingHandler) UpdateSettings(c *okapi.Context, req *UpdateUserSet
if req.Body.DailyReport != nil {
settings.DailyReport = *req.Body.DailyReport
}
+ if req.Body.NotifyBounceAlerts != nil {
+ settings.NotifyBounceAlerts = *req.Body.NotifyBounceAlerts
+ }
+ if req.Body.NotifyAPIKeyExpiry != nil {
+ settings.NotifyAPIKeyExpiry = *req.Body.NotifyAPIKeyExpiry
+ }
+ if req.Body.NotifyWorkspaceActivity != nil {
+ settings.NotifyWorkspaceActivity = *req.Body.NotifyWorkspaceActivity
+ }
if err := h.repo.CreateOrUpdate(settings); err != nil {
return c.AbortInternalServerError("failed to update settings", err)
diff --git a/internal/models/user_setting.go b/internal/models/user_setting.go
index 3499eae..8a5c0c1 100644
--- a/internal/models/user_setting.go
+++ b/internal/models/user_setting.go
@@ -21,19 +21,24 @@ import "time"
// UserSetting stores per-user preferences. Each user has at most one row.
type UserSetting struct {
- ID uint `json:"id" gorm:"primaryKey"`
- UserID uint `json:"user_id" gorm:"uniqueIndex;not null"`
- Timezone string `json:"timezone" gorm:"default:UTC"`
- DefaultSenderName string `json:"default_sender_name"`
- DefaultSenderEmail string `json:"default_sender_email"`
- EmailNotifications bool `json:"email_notifications" gorm:"default:true"`
- NotificationEmail string `json:"notification_email"`
- WebhookRetryCount int `json:"webhook_retry_count" gorm:"default:3"`
- DefaultTemplateID *uint `json:"default_template_id"`
- APIKeyExpiryDays int `json:"api_key_expiry_days" gorm:"default:90"`
- BounceAutoSuppress bool `json:"bounce_auto_suppress" gorm:"default:true"`
- DefaultLanguage string `json:"default_language" gorm:"size:10;default:'en'"`
- DailyReport bool `json:"daily_report" gorm:"default:false"`
- CreatedAt time.Time `json:"created_at"`
- UpdatedAt time.Time `json:"updated_at"`
+ ID uint `json:"id" gorm:"primaryKey"`
+ UserID uint `json:"user_id" gorm:"uniqueIndex;not null"`
+ Timezone string `json:"timezone" gorm:"default:UTC"`
+ DefaultSenderName string `json:"default_sender_name"`
+ DefaultSenderEmail string `json:"default_sender_email"`
+ EmailNotifications bool `json:"email_notifications" gorm:"default:true"`
+ NotificationEmail string `json:"notification_email"`
+ WebhookRetryCount int `json:"webhook_retry_count" gorm:"default:3"`
+ DefaultTemplateID *uint `json:"default_template_id"`
+ APIKeyExpiryDays int `json:"api_key_expiry_days" gorm:"default:90"`
+ BounceAutoSuppress bool `json:"bounce_auto_suppress" gorm:"default:true"`
+ DefaultLanguage string `json:"default_language" gorm:"size:10;default:'en'"`
+ DailyReport bool `json:"daily_report" gorm:"default:true"`
+
+ NotifyBounceAlerts bool `json:"notify_bounce_alerts" gorm:"default:true"`
+ NotifyAPIKeyExpiry bool `json:"notify_api_key_expiry" gorm:"default:true"`
+ NotifyWorkspaceActivity bool `json:"notify_workspace_activity" gorm:"default:true"`
+
+ CreatedAt time.Time `json:"created_at"`
+ UpdatedAt time.Time `json:"updated_at"`
}
diff --git a/internal/services/clientinfo/clientinfo.go b/internal/services/clientinfo/clientinfo.go
new file mode 100644
index 0000000..3b5babc
--- /dev/null
+++ b/internal/services/clientinfo/clientinfo.go
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2026 Jonas Kaninda
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package clientinfo
+
+import "strings"
+
+const unknown = "Unknown"
+
+// Client is a parsed, display-oriented view of a User-Agent string.
+type Client struct {
+ Browser string
+ OS string
+ Device string // form factor: "Desktop", "Mobile", "Tablet", or "Bot"
+}
+
+func Parse(ua string) Client {
+ if strings.TrimSpace(ua) == "" {
+ return Client{Browser: unknown, OS: unknown, Device: unknown}
+ }
+ return Client{
+ Browser: detectBrowser(ua),
+ OS: detectOS(ua),
+ Device: detectDevice(ua),
+ }
+}
+
+func (c Client) Label() string {
+ switch {
+ case c.Browser == unknown && c.OS == unknown:
+ return "Unknown device"
+ case c.OS == unknown:
+ return c.Browser
+ case c.Browser == unknown:
+ return c.OS
+ default:
+ return c.Browser + " on " + c.OS
+ }
+}
+
+func (c Client) Signature() string {
+ return c.Browser + "|" + c.OS
+}
+
+func detectBrowser(ua string) string {
+ switch {
+ case containsAny(ua, "Edg/", "Edge/", "EdgA/", "EdgiOS/"):
+ return "Edge"
+ case containsAny(ua, "OPR/", "Opera"):
+ return "Opera"
+ case strings.Contains(ua, "SamsungBrowser"):
+ return "Samsung Internet"
+ case strings.Contains(ua, "Firefox") || strings.Contains(ua, "FxiOS"):
+ return "Firefox"
+ case strings.Contains(ua, "CriOS") || strings.Contains(ua, "Chrome") || strings.Contains(ua, "Chromium"):
+ return "Chrome"
+ case strings.Contains(ua, "Safari"):
+ return "Safari"
+ case containsAny(ua, "curl/", "Wget", "PostmanRuntime", "Go-http-client", "python-requests"):
+ return "API client"
+ default:
+ return unknown
+ }
+}
+
+// detectOS checks OS tokens in priority order. iOS/iPadOS must be matched before
+// macOS, and Android before Linux, because of overlapping substrings.
+func detectOS(ua string) string {
+ switch {
+ case strings.Contains(ua, "Windows NT"), strings.Contains(ua, "Windows"):
+ return "Windows"
+ case containsAny(ua, "iPhone", "iPad", "iPod"):
+ return "iOS"
+ case strings.Contains(ua, "Android"):
+ return "Android"
+ case strings.Contains(ua, "CrOS"):
+ return "ChromeOS"
+ case strings.Contains(ua, "Mac OS X"), strings.Contains(ua, "Macintosh"):
+ return "macOS"
+ case strings.Contains(ua, "Linux"):
+ return "Linux"
+ default:
+ return unknown
+ }
+}
+
+// detectDevice resolves the form factor.
+func detectDevice(ua string) string {
+ switch {
+ case containsAny(ua, "bot", "Bot", "crawler", "spider", "Go-http-client", "curl/", "python-requests"):
+ return "Bot"
+ case strings.Contains(ua, "iPad"), strings.Contains(ua, "Tablet"):
+ return "Tablet"
+ case strings.Contains(ua, "Mobile"), strings.Contains(ua, "iPhone"), strings.Contains(ua, "Android"):
+ return "Mobile"
+ default:
+ return "Desktop"
+ }
+}
+
+func containsAny(s string, subs ...string) bool {
+ for _, sub := range subs {
+ if strings.Contains(s, sub) {
+ return true
+ }
+ }
+ return false
+}
diff --git a/internal/services/clientinfo/clientinfo_test.go b/internal/services/clientinfo/clientinfo_test.go
new file mode 100644
index 0000000..b0bfd57
--- /dev/null
+++ b/internal/services/clientinfo/clientinfo_test.go
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2026 Jonas Kaninda
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package clientinfo
+
+import "testing"
+
+func TestParse(t *testing.T) {
+ tests := []struct {
+ name string
+ ua string
+ wantBrowser string
+ wantOS string
+ wantDevice string
+ }{
+ {
+ name: "chrome on macos",
+ ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
+ wantBrowser: "Chrome", wantOS: "macOS", wantDevice: "Desktop",
+ },
+ {
+ // Edge carries both "Chrome" and "Safari" tokens; must resolve to Edge.
+ name: "edge on windows",
+ ua: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0",
+ wantBrowser: "Edge", wantOS: "Windows", wantDevice: "Desktop",
+ },
+ {
+ // Opera also carries a "Chrome" token.
+ name: "opera on windows",
+ ua: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 OPR/105.0.0.0",
+ wantBrowser: "Opera", wantOS: "Windows", wantDevice: "Desktop",
+ },
+ {
+ // Safari must not be misread as Chrome.
+ name: "safari on iphone",
+ ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Mobile/15E148 Safari/604.1",
+ wantBrowser: "Safari", wantOS: "iOS", wantDevice: "Mobile",
+ },
+ {
+ name: "chrome on android",
+ ua: "Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36",
+ wantBrowser: "Chrome", wantOS: "Android", wantDevice: "Mobile",
+ },
+ {
+ name: "firefox on linux",
+ ua: "Mozilla/5.0 (X11; Linux x86_64; rv:125.0) Gecko/20100101 Firefox/125.0",
+ wantBrowser: "Firefox", wantOS: "Linux", wantDevice: "Desktop",
+ },
+ {
+ name: "ipad is tablet",
+ ua: "Mozilla/5.0 (iPad; CPU OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/604.1",
+ wantBrowser: "Safari", wantOS: "iOS", wantDevice: "Tablet",
+ },
+ {
+ name: "api client",
+ ua: "curl/8.4.0",
+ wantBrowser: "API client", wantOS: "Unknown", wantDevice: "Bot",
+ },
+ {
+ name: "empty",
+ ua: "",
+ wantBrowser: "Unknown", wantOS: "Unknown", wantDevice: "Unknown",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := Parse(tt.ua)
+ if got.Browser != tt.wantBrowser {
+ t.Errorf("Browser = %q, want %q", got.Browser, tt.wantBrowser)
+ }
+ if got.OS != tt.wantOS {
+ t.Errorf("OS = %q, want %q", got.OS, tt.wantOS)
+ }
+ if got.Device != tt.wantDevice {
+ t.Errorf("Device = %q, want %q", got.Device, tt.wantDevice)
+ }
+ })
+ }
+}
+
+func TestLabelAndSignature(t *testing.T) {
+ c := Client{Browser: "Chrome", OS: "macOS", Device: "Desktop"}
+ if got := c.Label(); got != "Chrome on macOS" {
+ t.Errorf("Label() = %q, want %q", got, "Chrome on macOS")
+ }
+ if got := c.Signature(); got != "Chrome|macOS" {
+ t.Errorf("Signature() = %q, want %q", got, "Chrome|macOS")
+ }
+ if got := (Client{Browser: "Unknown", OS: "Unknown"}).Label(); got != "Unknown device" {
+ t.Errorf("Label() = %q, want %q", got, "Unknown device")
+ }
+}
diff --git a/internal/services/notification/preference_test.go b/internal/services/notification/preference_test.go
new file mode 100644
index 0000000..74aef87
--- /dev/null
+++ b/internal/services/notification/preference_test.go
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2026 Jonas Kaninda
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package notification
+
+import (
+ "testing"
+
+ "github.com/goposta/posta/internal/models"
+)
+
+func TestTemplateEnabled(t *testing.T) {
+ off := &models.UserSetting{
+ DailyReport: false,
+ NotifyBounceAlerts: false,
+ NotifyAPIKeyExpiry: false,
+ NotifyWorkspaceActivity: false,
+ }
+ on := &models.UserSetting{
+ DailyReport: true,
+ NotifyBounceAlerts: true,
+ NotifyAPIKeyExpiry: true,
+ NotifyWorkspaceActivity: true,
+ }
+
+ gated := map[string]struct{ enabledFlag bool }{
+ TemplateDailyReport: {},
+ TemplateBounceAlert: {},
+ TemplateAPIKeyExpiry: {},
+ TemplateRoleChanged: {},
+ }
+ for tmpl := range gated {
+ if templateEnabled(tmpl, off) {
+ t.Errorf("%s: want disabled when its flag is off", tmpl)
+ }
+ if !templateEnabled(tmpl, on) {
+ t.Errorf("%s: want enabled when its flag is on", tmpl)
+ }
+ }
+
+ for _, tmpl := range []string{
+ TemplateLoginAlert, TemplateTwoFactorChange, TemplateAccountDeletion,
+ TemplatePasswordChanged, TemplateWelcome, TemplateEmailVerify,
+ } {
+ if !templateEnabled(tmpl, off) {
+ t.Errorf("%s: must always be allowed (not user-toggleable)", tmpl)
+ }
+ }
+
+ if !templateEnabled("does_not_exist", off) {
+ t.Error("unknown template should default to allowed")
+ }
+}
diff --git a/internal/services/notification/service.go b/internal/services/notification/service.go
index 891bcf2..d8e387e 100644
--- a/internal/services/notification/service.go
+++ b/internal/services/notification/service.go
@@ -44,8 +44,25 @@ const (
TemplateBounceAlert = "bounce_alert"
TemplateRoleChanged = "role_changed"
TemplateEmailVerify = "email_verification"
+ TemplateLoginAlert = "login_alert"
+ TemplateTwoFactorChange = "two_factor_changed"
+ TemplateAccountDeletion = "account_deletion"
)
+var templatePreference = map[string]func(*models.UserSetting) bool{
+ TemplateDailyReport: func(s *models.UserSetting) bool { return s.DailyReport },
+ TemplateBounceAlert: func(s *models.UserSetting) bool { return s.NotifyBounceAlerts },
+ TemplateAPIKeyExpiry: func(s *models.UserSetting) bool { return s.NotifyAPIKeyExpiry },
+ TemplateRoleChanged: func(s *models.UserSetting) bool { return s.NotifyWorkspaceActivity },
+}
+
+func templateEnabled(templateName string, settings *models.UserSetting) bool {
+ if pref, ok := templatePreference[templateName]; ok {
+ return pref(settings)
+ }
+ return true
+}
+
// Service sends platform notification emails via the system SMTP server.
type Service struct {
smtpCfg config.SystemSMTPConfig
@@ -91,6 +108,9 @@ func (s *Service) loadTemplates() {
TemplateBounceAlert,
TemplateRoleChanged,
TemplateEmailVerify,
+ TemplateLoginAlert,
+ TemplateTwoFactorChange,
+ TemplateAccountDeletion,
}
for _, name := range names {
tmpl := template.Must(template.ParseFS(templateFS,
@@ -135,6 +155,20 @@ func (s *Service) Send(to, subject, templateName string, data map[string]any) er
// SendToUser sends a notification to a user, respecting their notification preferences.
func (s *Service) SendToUser(userID uint, subject, templateName string, data map[string]any) error {
+ return s.sendToUser(userID, subject, templateName, data, false)
+}
+
+// SendSecurityToUser sends a security-critical notification (sign-in alerts, 2FA
+// changes, password changes, account deletion). It bypasses the user's
+// EmailNotifications preference — these messages must always reach the account
+// owner — but still skips unverified accounts and honors their notification email.
+func (s *Service) SendSecurityToUser(userID uint, subject, templateName string, data map[string]any) error {
+ return s.sendToUser(userID, subject, templateName, data, true)
+}
+
+// sendToUser is the shared implementation behind SendToUser and SendSecurityToUser.
+// When security is true the recipient's EmailNotifications toggle is ignored.
+func (s *Service) sendToUser(userID uint, subject, templateName string, data map[string]any, security bool) error {
if !s.IsConfigured() {
return nil
}
@@ -149,11 +183,16 @@ func (s *Service) SendToUser(userID uint, subject, templateName string, data map
return fmt.Errorf("notification: settings for user %d: %w", userID, err)
}
- if !settings.EmailNotifications {
+ if !security && !settings.EmailNotifications {
logger.Debug("notification service: email notifications disabled for user", "user_id", userID)
return nil
}
+ if !security && !templateEnabled(templateName, settings) {
+ logger.Debug("notification service: notification type disabled for user", "user_id", userID, "template", templateName)
+ return nil
+ }
+
if templateName != TemplateEmailVerify && user.EmailVerifiedAt == nil {
logger.Debug("notification service: skipping send to unverified user", "user_id", userID, "template", templateName)
return nil
diff --git a/internal/services/notification/templates/account_deletion.tmpl b/internal/services/notification/templates/account_deletion.tmpl
new file mode 100644
index 0000000..4ce403c
--- /dev/null
+++ b/internal/services/notification/templates/account_deletion.tmpl
@@ -0,0 +1,21 @@
+{{ define "content" }}
+<h2 style="color: #111827; font-size: 20px; line-height: 1.3; margin: 0 0 18px; font-weight: 700; letter-spacing: -0.01em;">Your account is scheduled for deletion</h2>
+<p style="margin: 0 0 16px;">Hi {{ .UserName }},</p>
+<p class="lead" style="margin: 0 0 16px; font-size: 15px; color: #4b5563;">We've received a request to delete your {{ .AppName }} account. It has been deactivated now and will be <strong>permanently deleted on {{ .ScheduledFor }}</strong>.</p>
+
+<div class="alert-box alert-danger" style="padding: 14px 16px; border-radius: 10px; margin: 20px 0; font-size: 14px; line-height: 1.55; background-color: #fef2f2; border: 1px solid #fecaca; color: #991b1b;">
+ This action is permanent. Once deleted, your account, workspaces, and email history cannot be recovered.
+</div>
+
+<p style="margin: 0 0 16px;">Changed your mind? You can cancel the deletion and reactivate your account any time before the date above.</p>
+
+{{ if .AppURL }}
+<table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin: 28px auto;">
+ <tr><td align="center" bgcolor="#7c3aed" style="border-radius: 8px;">
+ <a href="{{ .AppURL }}/profile" class="btn" style="display: inline-block; padding: 13px 30px; background-color: #7c3aed; color: #ffffff !important; text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 15px; line-height: 1;">Cancel deletion</a>
+ </td></tr>
+</table>
+{{ end }}
+
+<p class="muted" style="margin: 0 0 16px; color: #6b7280; font-size: 13px;">If you didn't request this, cancel the deletion immediately and change your password.</p>
+{{ end }}
diff --git a/internal/services/notification/templates/api_key_created.tmpl b/internal/services/notification/templates/api_key_created.tmpl
index 187969d..e452f30 100644
--- a/internal/services/notification/templates/api_key_created.tmpl
+++ b/internal/services/notification/templates/api_key_created.tmpl
@@ -1,42 +1,44 @@
{{ define "content" }}
-<h2>New API Key Created</h2>
-<p>Hi {{ .UserName }},</p>
-<p>A new API key has been created on your account:</p>
+<h2 style="color: #111827; font-size: 20px; line-height: 1.3; margin: 0 0 18px; font-weight: 700; letter-spacing: -0.01em;">New API key created</h2>
+<p style="margin: 0 0 16px;">Hi {{ .UserName }},</p>
+<p class="lead" style="margin: 0 0 16px; font-size: 15px; color: #4b5563;">A new API key was just created on your account.</p>
-<table class="stats-table">
+<table class="stats-table" role="presentation" style="width: 100%; border-collapse: separate; border-spacing: 0; margin: 20px 0; border: 1px solid #eceef2; border-radius: 10px; overflow: hidden;">
<tr>
- <th>Detail</th>
- <th>Value</th>
+ <th style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; background-color: #f9fafb; color: #6b7280; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;">Detail</th>
+ <th style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; background-color: #f9fafb; color: #6b7280; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;">Value</th>
</tr>
<tr>
- <td>Name</td>
- <td><strong>{{ .KeyName }}</strong></td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">Name</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;"><strong>{{ .KeyName }}</strong></td>
</tr>
<tr>
- <td>Prefix</td>
- <td><code>{{ .KeyPrefix }}</code></td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">Prefix</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;"><code style="background-color: #f3f4f6; padding: 2px 7px; border-radius: 5px; font-family: 'SFMono-Regular', Consolas, monospace; font-size: 13px; color: #6d28d9;">{{ .KeyPrefix }}</code></td>
</tr>
<tr>
- <td>Expires</td>
- <td>{{ .ExpiresAt }}</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">Expires</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">{{ .ExpiresAt }}</td>
</tr>
<tr>
- <td>Created</td>
- <td>{{ .CreatedAt }}</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">Created</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">{{ .CreatedAt }}</td>
</tr>
<tr>
- <td>IP Address</td>
- <td>{{ .IPAddress }}</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">IP address</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">{{ .IPAddress }}</td>
</tr>
</table>
-<div class="alert-box alert-warning">
- <strong>Wasn't you?</strong> If you did not create this key, please revoke it immediately and review your account security.
+<div class="alert-box alert-warning" style="padding: 14px 16px; border-radius: 10px; margin: 20px 0; font-size: 14px; line-height: 1.55; background-color: #fffbeb; border: 1px solid #fde68a; color: #92400e;">
+ <strong>Didn't create this key?</strong> Revoke it immediately and review your account security.
</div>
{{ if .AppURL }}
-<p style="text-align: center; margin: 24px 0;">
- <a href="{{ .AppURL }}/api-keys" class="btn">Manage API Keys</a>
-</p>
+<table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin: 28px auto;">
+ <tr><td align="center" bgcolor="#7c3aed" style="border-radius: 8px;">
+ <a href="{{ .AppURL }}/api-keys" class="btn" style="display: inline-block; padding: 13px 30px; background-color: #7c3aed; color: #ffffff !important; text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 15px; line-height: 1;">Manage API keys</a>
+ </td></tr>
+</table>
{{ end }}
{{ end }}
diff --git a/internal/services/notification/templates/api_key_expiry.tmpl b/internal/services/notification/templates/api_key_expiry.tmpl
index a274921..52e892c 100644
--- a/internal/services/notification/templates/api_key_expiry.tmpl
+++ b/internal/services/notification/templates/api_key_expiry.tmpl
@@ -1,26 +1,30 @@
{{ define "content" }}
-<h2>API Key Expiring Soon</h2>
-<p>Hi {{ .UserName }},</p>
-<p>The following API {{ if eq .KeyCount 1 }}key is{{ else }}keys are{{ end }} in {{ if .WorkspaceName }}<strong>{{ .WorkspaceName }}</strong>{{ else }}your workspace{{ end }} expiring within the next 7 days:</p>
+<h2 style="color: #111827; font-size: 20px; line-height: 1.3; margin: 0 0 18px; font-weight: 700; letter-spacing: -0.01em;">API {{ if eq .KeyCount 1 }}key{{ else }}keys{{ end }} expiring soon</h2>
+<p style="margin: 0 0 16px;">Hi {{ .UserName }},</p>
+<p class="lead" style="margin: 0 0 16px; font-size: 15px; color: #4b5563;">The following API {{ if eq .KeyCount 1 }}key is{{ else }}keys are{{ end }} in {{ if .WorkspaceName }}<strong>{{ .WorkspaceName }}</strong>{{ else }}your workspace{{ end }} expiring within the next 7 days.</p>
-<table class="stats-table">
+<table class="stats-table" role="presentation" style="width: 100%; border-collapse: separate; border-spacing: 0; margin: 20px 0; border: 1px solid #eceef2; border-radius: 10px; overflow: hidden;">
<tr>
- <th>Key Name</th>
- <th>Expires</th>
+ <th style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; background-color: #f9fafb; color: #6b7280; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;">Key name</th>
+ <th style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; background-color: #f9fafb; color: #6b7280; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; text-align: right;">Expires</th>
</tr>
{{ range .Keys }}
<tr>
- <td>{{ .Name }}</td>
- <td>{{ .ExpiresAt }}</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;"><strong>{{ .Name }}</strong></td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827; text-align: right; color: #d97706;">{{ .ExpiresAt }}</td>
</tr>
{{ end }}
</table>
-<p>Please regenerate {{ if eq .KeyCount 1 }}this key{{ else }}these keys{{ end }} to avoid service interruption.</p>
+<div class="alert-box alert-warning" style="padding: 14px 16px; border-radius: 10px; margin: 20px 0; font-size: 14px; line-height: 1.55; background-color: #fffbeb; border: 1px solid #fde68a; color: #92400e;">
+ Regenerate {{ if eq .KeyCount 1 }}this key{{ else }}these keys{{ end }} before {{ if eq .KeyCount 1 }}it expires{{ else }}they expire{{ end }} to avoid service interruption.
+</div>
{{ if .AppURL }}
-<p style="text-align: center; margin: 24px 0;">
- <a href="{{ .AppURL }}/api-keys" class="btn">Manage API Keys</a>
-</p>
+<table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin: 28px auto;">
+ <tr><td align="center" bgcolor="#7c3aed" style="border-radius: 8px;">
+ <a href="{{ .AppURL }}/api-keys" class="btn" style="display: inline-block; padding: 13px 30px; background-color: #7c3aed; color: #ffffff !important; text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 15px; line-height: 1;">Manage API keys</a>
+ </td></tr>
+</table>
{{ end }}
{{ end }}
diff --git a/internal/services/notification/templates/base.tmpl b/internal/services/notification/templates/base.tmpl
index a9c2505..cc83476 100644
--- a/internal/services/notification/templates/base.tmpl
+++ b/internal/services/notification/templates/base.tmpl
@@ -1,45 +1,132 @@
{{ define "base" }}<!DOCTYPE html>
-<html lang="en">
+<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<meta http-equiv="X-UA-Compatible" content="IE=edge">
+<meta name="color-scheme" content="light dark">
+<meta name="supported-color-schemes" content="light dark">
<title>{{ .Subject }}</title>
+<!--[if mso]>
+<noscript><xml><o:OfficeDocumentSettings><o:PixelsPerInch>96</o:PixelsPerInch></o:OfficeDocumentSettings></xml></noscript>
+<![endif]-->
<style>
- body { margin: 0; padding: 0; background-color: #f4f4f7; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; }
- .wrapper { width: 100%; background-color: #f4f4f7; padding: 40px 0; }
- .container { max-width: 580px; margin: 0 auto; background-color: #ffffff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
- .header { background-color: #7c3aed; padding: 24px 32px; text-align: center; }
- .header h1 { color: #ffffff; margin: 0; font-size: 20px; font-weight: 600; }
- .body { padding: 32px; color: #374151; font-size: 15px; line-height: 1.6; }
- .body h2 { color: #111827; font-size: 18px; margin: 0 0 16px; }
+ :root { color-scheme: light dark; supported-color-schemes: light dark; }
+ body, table, td, a { -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
+ table, td { mso-table-lspace: 0pt; mso-table-rspace: 0pt; }
+ img { -ms-interpolation-mode: bicubic; border: 0; outline: none; text-decoration: none; }
+ body { margin: 0 !important; padding: 0 !important; width: 100% !important; background-color: #eef0f5; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; }
+
+ .wrapper { width: 100%; background-color: #eef0f5; padding: 32px 12px; }
+ .container { max-width: 600px; margin: 0 auto; background-color: #ffffff; border-radius: 12px; overflow: hidden; box-shadow: 0 1px 2px rgba(16,24,40,0.04), 0 4px 16px rgba(16,24,40,0.06); }
+
+ .header { background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%); background-color: #7c3aed; padding: 28px 32px; text-align: center; }
+ .header .brand { color: #ffffff; margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; text-decoration: none; }
+ .header .brand-dot { color: #c4b5fd; margin-left: 1px; }
+
+ .body { padding: 36px 32px 8px; color: #374151; font-size: 15px; line-height: 1.65; }
+ .body h2 { color: #111827; font-size: 20px; line-height: 1.3; margin: 0 0 18px; font-weight: 700; letter-spacing: -0.01em; }
.body p { margin: 0 0 16px; }
- .btn { display: inline-block; padding: 12px 28px; background-color: #7c3aed; color: #ffffff; text-decoration: none; border-radius: 6px; font-weight: 600; font-size: 14px; }
- .footer { padding: 24px 32px; text-align: center; font-size: 12px; color: #9ca3af; border-top: 1px solid #e5e7eb; }
- .stats-table { width: 100%; border-collapse: collapse; margin: 16px 0; }
- .stats-table th, .stats-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #e5e7eb; font-size: 14px; }
- .stats-table th { color: #6b7280; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
+ .body a { color: #7c3aed; }
+ .lead { font-size: 15px; color: #4b5563; }
+
+ /* Buttons */
+ .btn-wrap { margin: 28px 0; }
+ .btn { display: inline-block; padding: 13px 30px; background-color: #7c3aed; color: #ffffff !important; text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 15px; line-height: 1; }
+ .btn-secondary { display: inline-block; padding: 11px 26px; background-color: #ffffff; color: #7c3aed !important; text-decoration: none; border: 1px solid #d8b4fe; border-radius: 8px; font-weight: 600; font-size: 14px; line-height: 1; }
+
+ .footer { padding: 28px 32px 32px; text-align: center; font-size: 12px; line-height: 1.6; color: #9ca3af; border-top: 1px solid #eceef2; }
+ .footer a { color: #7c3aed; text-decoration: none; }
+ .footer .footer-links { margin: 0 0 10px; }
+ .footer .footer-links a { margin: 0 8px; font-weight: 600; }
+ .footer .footer-note { margin: 0 0 6px; color: #6b7280; }
+ .footer .footer-meta { margin: 10px 0 0; color: #b6bcc7; }
+
+ /* Stats / detail table */
+ .stats-table { width: 100%; border-collapse: separate; border-spacing: 0; margin: 20px 0; border: 1px solid #eceef2; border-radius: 10px; overflow: hidden; }
+ .stats-table th, .stats-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; }
+ .stats-table tr:last-child th, .stats-table tr:last-child td { border-bottom: 0; }
+ .stats-table th { background-color: #f9fafb; color: #6b7280; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.stats-table td { color: #111827; }
- .highlight { font-size: 28px; font-weight: 700; color: #7c3aed; }
+ .stats-table code { background-color: #f3f4f6; padding: 2px 7px; border-radius: 5px; font-family: 'SFMono-Regular', Consolas, monospace; font-size: 13px; color: #6d28d9; }
+
+ /* Highlight number */
+ .highlight { font-size: 30px; font-weight: 800; color: #7c3aed; letter-spacing: -0.02em; }
.muted { color: #6b7280; font-size: 13px; }
- .alert-box { padding: 16px; border-radius: 6px; margin: 16px 0; }
- .alert-warning { background-color: #fef3c7; border: 1px solid #fbbf24; color: #92400e; }
- .alert-danger { background-color: #fee2e2; border: 1px solid #fca5a5; color: #991b1b; }
- .alert-info { background-color: #eff6ff; border: 1px solid #93c5fd; color: #1e40af; }
+
+ /* Alert boxes */
+ .alert-box { padding: 14px 16px; border-radius: 10px; margin: 20px 0; font-size: 14px; line-height: 1.55; }
+ .alert-warning { background-color: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
+ .alert-danger { background-color: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
+ .alert-info { background-color: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }
+ .alert-success { background-color: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
+
+ /* Link fallback for buttons */
+ .link-fallback { word-break: break-all; font-size: 13px; }
+ .link-fallback a { color: #7c3aed; }
+
+ .divider { height: 1px; line-height: 1px; font-size: 1px; background-color: #eceef2; margin: 28px 0; }
+
+ @media only screen and (max-width: 600px) {
+ .wrapper { padding: 16px 0 !important; }
+ .container { border-radius: 0 !important; }
+ .body { padding: 28px 22px 4px !important; }
+ .header { padding: 24px 22px !important; }
+ .footer { padding: 24px 22px 28px !important; }
+ .body h2 { font-size: 19px !important; }
+ }
+
+ @media (prefers-color-scheme: dark) {
+ body, .wrapper { background-color: #0f1115 !important; }
+ .container { background-color: #1a1d24 !important; box-shadow: none !important; }
+ .body { color: #cbd2dd !important; }
+ .body h2 { color: #f3f4f6 !important; }
+ .lead { color: #aab2bf !important; }
+ .stats-table { border-color: #2a2e38 !important; }
+ .stats-table th { background-color: #20242c !important; color: #9aa3b2 !important; }
+ .stats-table th, .stats-table td { border-color: #2a2e38 !important; }
+ .stats-table td { color: #e5e7eb !important; }
+ .stats-table code { background-color: #2a2e38 !important; color: #c4b5fd !important; }
+ .footer { border-color: #2a2e38 !important; color: #7d8696 !important; }
+ .footer .footer-note { color: #9aa3b2 !important; }
+ .divider { background-color: #2a2e38 !important; }
+ }
</style>
</head>
<body>
-<div class="wrapper">
- <div class="container">
- <div class="header">
- <h1>{{ .AppName }}</h1>
- </div>
- <div class="body">
- {{ template "content" . }}
- </div>
- <div class="footer">
- {{ if .AppURL }}<a href="{{ .AppURL }}" style="color: #7c3aed; text-decoration: none;">{{ .AppName }}</a> &mdash; {{ end }}This is an automated notification.
- </div>
- </div>
+<div style="display: none; max-height: 0; overflow: hidden; mso-hide: all;">{{ if .Preheader }}{{ .Preheader }}{{ else }}{{ .Subject }}{{ end }}&#8199;&#65279;&#847;&#847;&#847;&#847;&#847;&#847;&#847;&#847;&#847;&#847;&#847;&#847;&#847;&#847;&#847;</div>
+<div class="wrapper" style="width: 100%; background-color: #eef0f5; padding: 32px 12px;">
+ <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
+ <tr>
+ <td align="center">
+ <table role="presentation" class="container" width="600" cellpadding="0" cellspacing="0" border="0" style="max-width: 600px; margin: 0 auto; background-color: #ffffff; border-radius: 12px; overflow: hidden; box-shadow: 0 1px 2px rgba(16,24,40,0.04), 0 4px 16px rgba(16,24,40,0.06);">
+ <tr>
+ <td class="header" style="background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%); background-color: #7c3aed; padding: 28px 32px; text-align: center;">
+ {{ if .AppURL }}<a class="brand" href="{{ .AppURL }}" style="color: #ffffff; margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; text-decoration: none;">{{ .AppName }}<span class="brand-dot" style="color: #c4b5fd; margin-left: 1px;">.</span></a>{{ else }}<span class="brand" style="color: #ffffff; margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; text-decoration: none;">{{ .AppName }}<span class="brand-dot" style="color: #c4b5fd; margin-left: 1px;">.</span></span>{{ end }}
+ </td>
+ </tr>
+ <tr>
+ <td class="body" style="padding: 36px 32px 8px; color: #374151; font-size: 15px; line-height: 1.65;">
+ {{ template "content" . }}
+ </td>
+ </tr>
+ <tr>
+ <td class="footer" style="padding: 28px 32px 32px; text-align: center; font-size: 12px; line-height: 1.6; color: #9ca3af; border-top: 1px solid #eceef2;">
+ {{ if .FooterNote }}<p class="footer-note" style="margin: 0 0 6px; color: #6b7280;">{{ .FooterNote }}</p>{{ end }}
+ <p class="footer-note" style="margin: 0 0 6px; color: #6b7280;">You're receiving this email because you have an account on {{ .AppName }}.</p>
+ {{ if .AppURL }}
+ <p class="footer-links" style="margin: 0 0 10px;">
+ <a href="{{ .AppURL }}" style="color: #7c3aed; text-decoration: none; margin: 0 8px; font-weight: 600;">Visit {{ .AppName }}</a>
+ <a href="{{ .AppURL }}/settings" style="color: #7c3aed; text-decoration: none; margin: 0 8px; font-weight: 600;">Notification settings</a>
+ </p>
+ {{ end }}
+ <p class="footer-meta" style="margin: 10px 0 0; color: #b6bcc7;">This is an automated message, please do not reply.</p>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
</div>
</body>
</html>{{ end }}
diff --git a/internal/services/notification/templates/bounce_alert.tmpl b/internal/services/notification/templates/bounce_alert.tmpl
index 5e5bfda..a701fac 100644
--- a/internal/services/notification/templates/bounce_alert.tmpl
+++ b/internal/services/notification/templates/bounce_alert.tmpl
@@ -1,35 +1,37 @@
{{ define "content" }}
-<h2>Bounce Rate Alert</h2>
-<p>Hi {{ .UserName }},</p>
+<h2 style="color: #111827; font-size: 20px; line-height: 1.3; margin: 0 0 18px; font-weight: 700; letter-spacing: -0.01em;">Bounce rate alert</h2>
+<p style="margin: 0 0 16px;">Hi {{ .UserName }},</p>
-<div class="alert-box alert-danger">
- The bounce rate {{ if .WorkspaceName }}for <strong>{{ .WorkspaceName }}</strong> {{ end }}in the last 24 hours is <strong>{{ .BounceRate }}%</strong>, which exceeds the {{ .Threshold }}% threshold.
+<div class="alert-box alert-danger" style="padding: 14px 16px; border-radius: 10px; margin: 20px 0; font-size: 14px; line-height: 1.55; background-color: #fef2f2; border: 1px solid #fecaca; color: #991b1b;">
+ The bounce rate {{ if .WorkspaceName }}for <strong>{{ .WorkspaceName }}</strong> {{ end }}over the last 24 hours is <strong>{{ .BounceRate }}%</strong>, exceeding your {{ .Threshold }}% threshold.
</div>
-<table class="stats-table">
+<table class="stats-table" role="presentation" style="width: 100%; border-collapse: separate; border-spacing: 0; margin: 20px 0; border: 1px solid #eceef2; border-radius: 10px; overflow: hidden;">
<tr>
- <th>Metric</th>
- <th style="text-align: right;">Count</th>
+ <th style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; background-color: #f9fafb; color: #6b7280; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;">Metric (24h)</th>
+ <th style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; background-color: #f9fafb; color: #6b7280; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; text-align: right;">Count</th>
</tr>
<tr>
- <td>Total Emails (24h)</td>
- <td style="text-align: right;">{{ .TotalEmails }}</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">Total emails</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827; text-align: right;">{{ .TotalEmails }}</td>
</tr>
<tr>
- <td>Bounces</td>
- <td style="text-align: right; color: #dc2626;">{{ .BounceCount }}</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">Bounces</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827; text-align: right; color: #dc2626; font-weight: 600;">{{ .BounceCount }}</td>
</tr>
<tr>
- <td>New Suppressions</td>
- <td style="text-align: right; color: #d97706;">{{ .SuppressionCount }}</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">New suppressions</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827; text-align: right; color: #d97706; font-weight: 600;">{{ .SuppressionCount }}</td>
</tr>
</table>
-<p>High bounce rates can damage your sender reputation. Consider reviewing your recipient lists and removing invalid addresses.</p>
+<p style="margin: 0 0 16px;">High bounce rates can damage your sender reputation. Review your recipient lists and remove invalid or unengaged addresses.</p>
{{ if .AppURL }}
-<p style="text-align: center; margin: 24px 0;">
- <a href="{{ .AppURL }}/bounces" class="btn">Review Bounces</a>
-</p>
+<table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin: 28px auto;">
+ <tr><td align="center" bgcolor="#7c3aed" style="border-radius: 8px;">
+ <a href="{{ .AppURL }}/bounces" class="btn" style="display: inline-block; padding: 13px 30px; background-color: #7c3aed; color: #ffffff !important; text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 15px; line-height: 1;">Review bounces</a>
+ </td></tr>
+</table>
{{ end }}
{{ end }}
diff --git a/internal/services/notification/templates/daily_report.tmpl b/internal/services/notification/templates/daily_report.tmpl
index 6579be0..5db807f 100644
--- a/internal/services/notification/templates/daily_report.tmpl
+++ b/internal/services/notification/templates/daily_report.tmpl
@@ -1,45 +1,52 @@
{{ define "content" }}
-<h2>Daily Email Report</h2>
-<p>Here's the email activity summary{{ if .WorkspaceName }} for <strong>{{ .WorkspaceName }}</strong>{{ end }} on <strong>{{ .ReportDate }}</strong>.</p>
+<h2 style="color: #111827; font-size: 20px; line-height: 1.3; margin: 0 0 18px; font-weight: 700; letter-spacing: -0.01em;">Daily email report</h2>
+<p class="lead" style="margin: 0 0 16px; font-size: 15px; color: #4b5563;">Here's your email activity summary{{ if .WorkspaceName }} for <strong>{{ .WorkspaceName }}</strong>{{ end }} on <strong>{{ .ReportDate }}</strong>.</p>
-<table class="stats-table">
+{{ if gt .TotalEmails 0 }}
+<p style="text-align: center; margin: 24px 0 4px;">
+ <span class="highlight" style="font-size: 30px; font-weight: 800; color: #7c3aed; letter-spacing: -0.02em;">{{ .DeliveryRate }}%</span><br>
+ <span class="muted" style="color: #6b7280; font-size: 13px;">delivery rate</span>
+</p>
+{{ end }}
+
+<table class="stats-table" role="presentation" style="width: 100%; border-collapse: separate; border-spacing: 0; margin: 20px 0; border: 1px solid #eceef2; border-radius: 10px; overflow: hidden;">
<tr>
- <th>Metric</th>
- <th style="text-align: right;">Count</th>
+ <th style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; background-color: #f9fafb; color: #6b7280; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;">Metric</th>
+ <th style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; background-color: #f9fafb; color: #6b7280; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; text-align: right;">Count</th>
</tr>
<tr>
- <td>Total Emails</td>
- <td style="text-align: right;"><strong>{{ .TotalEmails }}</strong></td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">Total emails</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827; text-align: right;"><strong>{{ .TotalEmails }}</strong></td>
</tr>
<tr>
- <td>Sent</td>
- <td style="text-align: right; color: #059669;">{{ .SentEmails }}</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">Sent</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827; text-align: right; color: #059669; font-weight: 600;">{{ .SentEmails }}</td>
</tr>
<tr>
- <td>Failed</td>
- <td style="text-align: right; color: #dc2626;">{{ .FailedEmails }}</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">Failed</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827; text-align: right; color: #dc2626; font-weight: 600;">{{ .FailedEmails }}</td>
</tr>
<tr>
- <td>Bounced</td>
- <td style="text-align: right; color: #d97706;">{{ .BouncedEmails }}</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">Bounced</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827; text-align: right; color: #d97706; font-weight: 600;">{{ .BouncedEmails }}</td>
</tr>
<tr>
- <td>Suppressed</td>
- <td style="text-align: right; color: #6b7280;">{{ .SuppressedEmails }}</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">Suppressed</td>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827; text-align: right; color: #6b7280;">{{ .SuppressedEmails }}</td>
</tr>
</table>
-{{ if gt .TotalEmails 0 }}
-<p>Delivery rate: <span class="highlight">{{ .DeliveryRate }}%</span></p>
-{{ else }}
-<p class="muted">No emails were sent during this period.</p>
+{{ if eq .TotalEmails 0 }}
+<p class="muted" style="margin: 0 0 16px; color: #6b7280; font-size: 13px;">No emails were sent during this period.</p>
{{ end }}
{{ if .AppURL }}
-<p style="text-align: center; margin-top: 24px;">
- <a href="{{ .AppURL }}" class="btn">View Dashboard</a>
-</p>
+<table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin: 28px auto;">
+ <tr><td align="center" bgcolor="#7c3aed" style="border-radius: 8px;">
+ <a href="{{ .AppURL }}/analytics" class="btn" style="display: inline-block; padding: 13px 30px; background-color: #7c3aed; color: #ffffff !important; text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 15px; line-height: 1;">View dashboard</a>
+ </td></tr>
+</table>
{{ end }}
-<p class="muted" style="margin-top: 24px;">You receive this report as an owner or admin of this workspace.</p>
+<p class="muted" style="margin: 0 0 16px; color: #6b7280; font-size: 13px; text-align: center;">You receive this report because you're an owner or admin of this workspace.</p>
{{ end }}
diff --git a/internal/services/notification/templates/email_verification.tmpl b/internal/services/notification/templates/email_verification.tmpl
index 6d28745..e68fa7f 100644
--- a/internal/services/notification/templates/email_verification.tmpl
+++ b/internal/services/notification/templates/email_verification.tmpl
@@ -1,14 +1,19 @@
{{ define "content" }}
-<h2>Verify your email address</h2>
-<p>Hi {{ .UserName }},</p>
-<p>To finish setting up your {{ .AppName }} account, please confirm this is your email address by clicking the button below.</p>
+<h2 style="color: #111827; font-size: 20px; line-height: 1.3; margin: 0 0 18px; font-weight: 700; letter-spacing: -0.01em;">Verify your email address</h2>
+<p style="margin: 0 0 16px;">Hi {{ .UserName }},</p>
+<p class="lead" style="margin: 0 0 16px; font-size: 15px; color: #4b5563;">To finish setting up your {{ .AppName }} account, please confirm this is your email address.</p>
-<p style="text-align: center; margin: 32px 0;">
- <a href="{{ .VerifyURL }}" class="btn">Verify email</a>
-</p>
+{{ if .VerifyURL }}
+<table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin: 28px auto;">
+ <tr><td align="center" bgcolor="#7c3aed" style="border-radius: 8px;">
+ <a href="{{ .VerifyURL }}" class="btn" style="display: inline-block; padding: 13px 30px; background-color: #7c3aed; color: #ffffff !important; text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 15px; line-height: 1;">Verify email address</a>
+ </td></tr>
+</table>
-<p class="muted">Or paste this link into your browser:<br>
-<a href="{{ .VerifyURL }}">{{ .VerifyURL }}</a></p>
+<p class="muted" style="margin: 0 0 16px; color: #6b7280; font-size: 13px;">Or paste this link into your browser:</p>
+<p class="link-fallback" style="margin: 0 0 16px; word-break: break-all; font-size: 13px;"><a href="{{ .VerifyURL }}" style="color: #7c3aed;">{{ .VerifyURL }}</a></p>
+{{ end }}
-<p class="muted">This link expires in {{ .ExpiryHours }} hours. If you didn't create an account, you can safely ignore this email.</p>
+<div class="divider" style="height: 1px; line-height: 1px; font-size: 1px; background-color: #eceef2; margin: 28px 0;"></div>
+<p class="muted" style="margin: 0 0 16px; color: #6b7280; font-size: 13px;">This link expires in {{ .ExpiryHours }} hours. If you didn't create an account, you can safely ignore this email.</p>
{{ end }}
diff --git a/internal/services/notification/templates/login_alert.tmpl b/internal/services/notification/templates/login_alert.tmpl
new file mode 100644
index 0000000..3832632
--- /dev/null
+++ b/internal/services/notification/templates/login_alert.tmpl
@@ -0,0 +1,30 @@
+{{ define "content" }}
+<h2 style="color: #111827; font-size: 20px; line-height: 1.3; margin: 0 0 18px; font-weight: 700; letter-spacing: -0.01em;">New sign-in to your account</h2>
+<p style="margin: 0 0 16px;">Hi {{ .UserName }},</p>
+<p class="lead" style="margin: 0 0 16px; font-size: 15px; color: #4b5563;">Your {{ .AppName }} account was just accessed from a new device or location.</p>
+
+<table class="stats-table" role="presentation" style="width: 100%; border-collapse: separate; border-spacing: 0; margin: 20px 0; border: 1px solid #eceef2; border-radius: 10px; overflow: hidden;">
+ <tr>
+ <th style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; background-color: #f9fafb; color: #6b7280; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;">Detail</th>
+ <th style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; background-color: #f9fafb; color: #6b7280; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;">Value</th>
+ </tr>
+ {{ if .Browser }}<tr><td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">Browser</td><td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;"><strong>{{ .Browser }}</strong></td></tr>{{ end }}
+ {{ if .OS }}<tr><td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">Operating system</td><td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">{{ .OS }}</td></tr>{{ end }}
+ {{ if .Device }}<tr><td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">Device</td><td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">{{ .Device }}</td></tr>{{ end }}
+ {{ if .Location }}<tr><td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">Location</td><td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">{{ .Location }}</td></tr>{{ end }}
+ <tr><td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">IP address</td><td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;"><code style="background-color: #f3f4f6; padding: 2px 7px; border-radius: 5px; font-family: 'SFMono-Regular', Consolas, monospace; font-size: 13px; color: #6d28d9;">{{ .IPAddress }}</code></td></tr>
+ <tr><td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">Time</td><td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;">{{ .LoginAt }}</td></tr>
+</table>
+
+<div class="alert-box alert-warning" style="padding: 14px 16px; border-radius: 10px; margin: 20px 0; font-size: 14px; line-height: 1.55; background-color: #fffbeb; border: 1px solid #fde68a; color: #92400e;">
+ <strong>Wasn't you?</strong> Change your password and revoke active sessions right away to keep your account secure.
+</div>
+
+{{ if .AppURL }}
+<table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin: 28px auto;">
+ <tr><td align="center" bgcolor="#7c3aed" style="border-radius: 8px;">
+ <a href="{{ .AppURL }}/profile" class="btn" style="display: inline-block; padding: 13px 30px; background-color: #7c3aed; color: #ffffff !important; text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 15px; line-height: 1;">Review account activity</a>
+ </td></tr>
+</table>
+{{ end }}
+{{ end }}
diff --git a/internal/services/notification/templates/password_changed.tmpl b/internal/services/notification/templates/password_changed.tmpl
index dd3386a..29d51ab 100644
--- a/internal/services/notification/templates/password_changed.tmpl
+++ b/internal/services/notification/templates/password_changed.tmpl
@@ -1,15 +1,17 @@
{{ define "content" }}
-<h2>Password Changed</h2>
-<p>Hi {{ .UserName }},</p>
-<p>Your password was successfully changed on <strong>{{ .ChangedAt }}</strong>.</p>
+<h2 style="color: #111827; font-size: 20px; line-height: 1.3; margin: 0 0 18px; font-weight: 700; letter-spacing: -0.01em;">Your password was changed</h2>
+<p style="margin: 0 0 16px;">Hi {{ .UserName }},</p>
+<p class="lead" style="margin: 0 0 16px; font-size: 15px; color: #4b5563;">Your {{ .AppName }} password was successfully changed on <strong>{{ .ChangedAt }}</strong>.</p>
-<div class="alert-box alert-warning">
- <strong>Wasn't you?</strong> If you did not make this change, please secure your account immediately by resetting your password and reviewing your active sessions.
+<div class="alert-box alert-warning" style="padding: 14px 16px; border-radius: 10px; margin: 20px 0; font-size: 14px; line-height: 1.55; background-color: #fffbeb; border: 1px solid #fde68a; color: #92400e;">
+ <strong>Didn't make this change?</strong> Secure your account right away: reset your password and review your active sessions.
</div>
{{ if .AppURL }}
-<p style="text-align: center; margin: 24px 0;">
- <a href="{{ .AppURL }}/profile" class="btn">Review Account</a>
-</p>
+<table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin: 28px auto;">
+ <tr><td align="center" bgcolor="#7c3aed" style="border-radius: 8px;">
+ <a href="{{ .AppURL }}/profile" class="btn" style="display: inline-block; padding: 13px 30px; background-color: #7c3aed; color: #ffffff !important; text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 15px; line-height: 1;">Review account security</a>
+ </td></tr>
+</table>
{{ end }}
{{ end }}
diff --git a/internal/services/notification/templates/role_changed.tmpl b/internal/services/notification/templates/role_changed.tmpl
index 96eb3fc..d4e89d4 100644
--- a/internal/services/notification/templates/role_changed.tmpl
+++ b/internal/services/notification/templates/role_changed.tmpl
@@ -1,15 +1,17 @@
{{ define "content" }}
-<h2>Workspace Role Updated</h2>
-<p>Hi {{ .UserName }},</p>
-<p>Your role in the workspace <strong>"{{ .WorkspaceName }}"</strong> has been changed from <strong>{{ .OldRole }}</strong> to <strong>{{ .NewRole }}</strong> by {{ .ChangedBy }}.</p>
+<h2 style="color: #111827; font-size: 20px; line-height: 1.3; margin: 0 0 18px; font-weight: 700; letter-spacing: -0.01em;">Your workspace role was updated</h2>
+<p style="margin: 0 0 16px;">Hi {{ .UserName }},</p>
+<p class="lead" style="margin: 0 0 16px; font-size: 15px; color: #4b5563;">Your role in <strong>"{{ .WorkspaceName }}"</strong> was changed from <strong>{{ .OldRole }}</strong> to <strong>{{ .NewRole }}</strong> by {{ .ChangedBy }}.</p>
-<div class="alert-box alert-info">
+<div class="alert-box alert-info" style="padding: 14px 16px; border-radius: 10px; margin: 20px 0; font-size: 14px; line-height: 1.55; background-color: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af;">
Your new permissions as <strong>{{ .NewRole }}</strong> are now active.
</div>
{{ if .AppURL }}
-<p style="text-align: center; margin: 24px 0;">
- <a href="{{ .AppURL }}/workspaces" class="btn">View Workspaces</a>
-</p>
+<table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin: 28px auto;">
+ <tr><td align="center" bgcolor="#7c3aed" style="border-radius: 8px;">
+ <a href="{{ .AppURL }}/workspaces" class="btn" style="display: inline-block; padding: 13px 30px; background-color: #7c3aed; color: #ffffff !important; text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 15px; line-height: 1;">View workspace</a>
+ </td></tr>
+</table>
{{ end }}
{{ end }}
diff --git a/internal/services/notification/templates/two_factor_changed.tmpl b/internal/services/notification/templates/two_factor_changed.tmpl
new file mode 100644
index 0000000..95a932c
--- /dev/null
+++ b/internal/services/notification/templates/two_factor_changed.tmpl
@@ -0,0 +1,23 @@
+{{ define "content" }}
+<h2 style="color: #111827; font-size: 20px; line-height: 1.3; margin: 0 0 18px; font-weight: 700; letter-spacing: -0.01em;">Two-factor authentication {{ .Action }}</h2>
+<p style="margin: 0 0 16px;">Hi {{ .UserName }},</p>
+<p class="lead" style="margin: 0 0 16px; font-size: 15px; color: #4b5563;">Two-factor authentication (2FA) was <strong>{{ .Action }}</strong> on your {{ .AppName }} account on <strong>{{ .ChangedAt }}</strong>.</p>
+
+{{ if eq .Action "enabled" }}
+<div class="alert-box alert-success" style="padding: 14px 16px; border-radius: 10px; margin: 20px 0; font-size: 14px; line-height: 1.55; background-color: #f0fdf4; border: 1px solid #bbf7d0; color: #166534;">
+ <strong>Your account is now better protected.</strong> You'll be asked for a verification code from your authenticator app each time you sign in.
+</div>
+{{ else }}
+<div class="alert-box alert-warning" style="padding: 14px 16px; border-radius: 10px; margin: 20px 0; font-size: 14px; line-height: 1.55; background-color: #fffbeb; border: 1px solid #fde68a; color: #92400e;">
+ <strong>Your account is now less protected.</strong> If you didn't disable 2FA, re-enable it immediately and change your password.
+</div>
+{{ end }}
+
+{{ if .AppURL }}
+<table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin: 28px auto;">
+ <tr><td align="center" bgcolor="#7c3aed" style="border-radius: 8px;">
+ <a href="{{ .AppURL }}/profile" class="btn" style="display: inline-block; padding: 13px 30px; background-color: #7c3aed; color: #ffffff !important; text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 15px; line-height: 1;">Manage security settings</a>
+ </td></tr>
+</table>
+{{ end }}
+{{ end }}
diff --git a/internal/services/notification/templates/welcome.tmpl b/internal/services/notification/templates/welcome.tmpl
index a0d3891..75bcac8 100644
--- a/internal/services/notification/templates/welcome.tmpl
+++ b/internal/services/notification/templates/welcome.tmpl
@@ -1,13 +1,27 @@
{{ define "content" }}
-<h2>Welcome to {{ .AppName }}!</h2>
-<p>Hi {{ .UserName }},</p>
-<p>Your account has been created successfully. You can now start sending emails, managing templates, and configuring your workspace.</p>
+<h2 style="color: #111827; font-size: 20px; line-height: 1.3; margin: 0 0 18px; font-weight: 700; letter-spacing: -0.01em;">Welcome to {{ .AppName }}</h2>
+<p style="margin: 0 0 16px;">Hi {{ .UserName }},</p>
+<p class="lead" style="margin: 0 0 16px; font-size: 15px; color: #4b5563;">Your account is ready. You can now send transactional and marketing email, manage templates and contacts, and track delivery in real time.</p>
+
+<table class="stats-table" role="presentation" style="width: 100%; border-collapse: separate; border-spacing: 0; margin: 20px 0; border: 1px solid #eceef2; border-radius: 10px; overflow: hidden;">
+ <tr>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;"><strong>1.</strong>&nbsp; Verify a sending domain to start delivering email</td>
+ </tr>
+ <tr>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;"><strong>2.</strong>&nbsp; Create an API key and send your first message</td>
+ </tr>
+ <tr>
+ <td style="padding: 12px 16px; text-align: left; border-bottom: 1px solid #eceef2; font-size: 14px; color: #111827;"><strong>3.</strong>&nbsp; Invite your team and set notification preferences</td>
+ </tr>
+</table>
{{ if .AppURL }}
-<p style="text-align: center; margin: 32px 0;">
- <a href="{{ .AppURL }}" class="btn">Go to Dashboard</a>
-</p>
+<table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin: 28px auto;">
+ <tr><td align="center" bgcolor="#7c3aed" style="border-radius: 8px;">
+ <a href="{{ .AppURL }}" class="btn" style="display: inline-block; padding: 13px 30px; background-color: #7c3aed; color: #ffffff !important; text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 15px; line-height: 1;">Go to dashboard</a>
+ </td></tr>
+</table>
{{ end }}
-<p class="muted">If you didn't create this account, please ignore this email.</p>
+<p class="muted" style="margin: 0 0 16px; color: #6b7280; font-size: 13px;">If you didn't create this account, you can safely ignore this email.</p>
{{ end }}
diff --git a/internal/services/notification/templates/workspace_invitation.tmpl b/internal/services/notification/templates/workspace_invitation.tmpl
index 239dcff..d0af73b 100644
--- a/internal/services/notification/templates/workspace_invitation.tmpl
+++ b/internal/services/notification/templates/workspace_invitation.tmpl
@@ -1,12 +1,18 @@
{{ define "content" }}
-<h2>You've been invited to a workspace</h2>
-<p><strong>{{ .InviterName }}</strong> has invited you to join the workspace <strong>"{{ .WorkspaceName }}"</strong> as {{ .RoleArticle }} <strong>{{ .Role }}</strong>.</p>
+<h2 style="color: #111827; font-size: 20px; line-height: 1.3; margin: 0 0 18px; font-weight: 700; letter-spacing: -0.01em;">You've been invited to a workspace</h2>
+<p class="lead" style="margin: 0 0 16px; font-size: 15px; color: #4b5563;"><strong>{{ .InviterName }}</strong> has invited you to join <strong>"{{ .WorkspaceName }}"</strong> on {{ .AppName }} as {{ .RoleArticle }} <strong>{{ .Role }}</strong>.</p>
{{ if .AcceptURL }}
-<p style="text-align: center; margin: 32px 0;">
- <a href="{{ .AcceptURL }}" class="btn">Accept Invitation</a>
-</p>
+<table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin: 28px auto;">
+ <tr><td align="center" bgcolor="#7c3aed" style="border-radius: 8px;">
+ <a href="{{ .AcceptURL }}" class="btn" style="display: inline-block; padding: 13px 30px; background-color: #7c3aed; color: #ffffff !important; text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 15px; line-height: 1;">Accept invitation</a>
+ </td></tr>
+</table>
+
+<p class="muted" style="margin: 0 0 16px; color: #6b7280; font-size: 13px;">Or paste this link into your browser:</p>
+<p class="link-fallback" style="margin: 0 0 16px; word-break: break-all; font-size: 13px;"><a href="{{ .AcceptURL }}" style="color: #7c3aed;">{{ .AcceptURL }}</a></p>
{{ end }}
-<p class="muted">This invitation expires on {{ .ExpiresAt }}. If you don't have an account, you'll need to register first.</p>
+<div class="divider" style="height: 1px; line-height: 1px; font-size: 1px; background-color: #eceef2; margin: 28px 0;"></div>
+<p class="muted" style="margin: 0 0 16px; color: #6b7280; font-size: 13px;">This invitation expires on {{ .ExpiresAt }}. If you don't have an account yet, you'll be prompted to create one first.</p>
{{ end }}
diff --git a/internal/services/workspacemigrate/migrate.go b/internal/services/workspacemigrate/migrate.go
index 5a3b451..95b8b53 100644
--- a/internal/services/workspacemigrate/migrate.go
+++ b/internal/services/workspacemigrate/migrate.go
@@ -28,9 +28,6 @@ import (
"gorm.io/gorm"
)
-// operationalTables are the user-scoped resources whose rows are re-scoped to
-// the personal workspace. Each has a `user_id NOT NULL` + nullable `workspace_id`.
-// Order is irrelevant — every table is backfilled by user_id in one pass.
var operationalTables = []interface{}{
&models.APIKey{},
&models.Template{},
@@ -50,23 +47,14 @@ var operationalTables = []interface{}{
&models.Campaign{},
}
-// Seeder provisions default content (stylesheet, templates, languages) for a
-// freshly-created personal workspace. Implemented by services/seeder.Seeder.
-// It is only invoked on the per-user hook path (register/login/oauth), not the
-// bulk backfill — existing users already own their content.
type Seeder interface {
SeedWorkspaceDefaults(workspaceID, userID uint, userName string)
}
// Service performs personal-workspace migrations.
type Service struct {
- // planEnforcement mirrors config.PlanEnforcement. When true a default plan
- // must exist and is assigned to each personal workspace; when false (OSS
- // default) workspaces get plan_id = NULL. See plan §1.
planEnforcement bool
- // seeder, when set, seeds default content into a newly-created personal
- // workspace after MigrateUser commits. nil on the backfill path.
seeder Seeder
}
@@ -75,9 +63,6 @@ func New(planEnforcement bool) *Service {
return &Service{planEnforcement: planEnforcement}
}
-// SetSeeder attaches a seeder so MigrateUser provisions default content for new
-// personal workspaces. Folds the old fire-and-forget SeedUserDefaults call into
-// the migration (§4).
func (s *Service) SetSeeder(seeder Seeder) {
s.seeder = seeder
}
@@ -103,9 +88,6 @@ func (s *Service) MigrateUser(db *gorm.DB, userID uint) (uint, error) {
return 0, err
}
- // Seed default content after commit so the workspace row is visible. The
- // seeder is idempotent (skips users who already own templates), so this is a
- // no-op for users who were re-scoped rather than freshly created.
if s.seeder != nil {
s.seeder.SeedWorkspaceDefaults(wsID, userID, existing.Name)
}
diff --git a/internal/services/workspacemigrate/migrate_test.go b/internal/services/workspacemigrate/migrate_test.go
index 22c469b..89366fb 100644
--- a/internal/services/workspacemigrate/migrate_test.go
+++ b/internal/services/workspacemigrate/migrate_test.go
@@ -24,11 +24,6 @@ import (
"github.com/goposta/posta/internal/models"
)
-// The transactional migration itself is exercised against a live Postgres (it
-// relies on SAVEPOINTs and the partial unique index, which an in-memory engine
-// won't replicate). These unit tests cover the pure pieces that are easy to get
-// wrong without a database.
-
func TestPersonalSlugIsStableAndUnique(t *testing.T) {
if got := personalSlug(42); got != "personal-42" {
t.Fatalf("personalSlug(42) = %q, want %q", got, "personal-42")
@@ -38,9 +33,6 @@ func TestPersonalSlugIsStableAndUnique(t *testing.T) {
}
}
-// TestOperationalTablesMatchPlan guards against silently dropping a table from
-// the backfill — every user-scoped operational resource listed in §3 of the
-// plan must be present, and each must actually carry a workspace_id column.
func TestOperationalTablesMatchPlan(t *testing.T) {
want := []interface{}{
&models.APIKey{}, &models.Template{}, &models.StyleSheet{}, &models.Language{},
diff --git a/internal/storage/migration/upgrade/step.go b/internal/storage/migration/upgrade/step.go
index b507507..964a6db 100644
--- a/internal/storage/migration/upgrade/step.go
+++ b/internal/storage/migration/upgrade/step.go
@@ -19,21 +19,6 @@ package upgrade
import "gorm.io/gorm"
-// Step is a one-shot data migration that runs at boot time, exactly once per
-// database. Schema migrations stay in GORM AutoMigrate; this registry is for
-// data backfills, defaults, and cleanup that AutoMigrate cannot express.
-//
-// Rules each step author must follow:
-//
-// 1. ID is permanent. Once a step ships, never rename or delete its ID —
-// that's how the registry knows the step has already been applied.
-// Use a date-prefixed slug, e.g. "2026-05-30-mark-default-plan".
-// 2. Apply must be idempotent in spirit even though the framework guarantees
-// single-run, because a step that crashes mid-way will retry on the next
-// boot. Use INSERT … ON CONFLICT DO NOTHING, WHERE NOT EXISTS, etc.
-// 3. Apply runs inside its own transaction; do not start one yourself.
-// 4. If a step is wrong after it ships, write a follow-up step that fixes
-// forward. Do not retroactively edit a step's Apply.
type Step struct {
ID string
Apply func(tx *gorm.DB) error
@@ -52,8 +37,6 @@ var registry = []Step{
},
}
-// Registry returns a copy of the registered steps so callers (status command,
-// tests) can inspect the list without mutating it.
func Registry() []Step {
out := make([]Step, len(registry))
copy(out, registry)
diff --git a/internal/storage/repositories/user_setting_repo.go b/internal/storage/repositories/user_setting_repo.go
index 55d67e9..3f427b7 100644
--- a/internal/storage/repositories/user_setting_repo.go
+++ b/internal/storage/repositories/user_setting_repo.go
@@ -39,12 +39,16 @@ func (r *UserSettingRepository) FindByUserID(userID uint) (*models.UserSetting,
}
if result.Error == gorm.ErrRecordNotFound {
setting = models.UserSetting{
- UserID: userID,
- Timezone: "UTC",
- EmailNotifications: true,
- WebhookRetryCount: 3,
- APIKeyExpiryDays: 90,
- BounceAutoSuppress: true,
+ UserID: userID,
+ Timezone: "UTC",
+ EmailNotifications: true,
+ WebhookRetryCount: 3,
+ APIKeyExpiryDays: 90,
+ BounceAutoSuppress: true,
+ DailyReport: true,
+ NotifyBounceAlerts: true,
+ NotifyAPIKeyExpiry: true,
+ NotifyWorkspaceActivity: true,
}
if err := r.db.Create(&setting).Error; err != nil {
return nil, err
@@ -58,14 +62,3 @@ func (r *UserSettingRepository) FindByUserID(userID uint) (*models.UserSetting,
func (r *UserSettingRepository) CreateOrUpdate(setting *models.UserSetting) error {
return r.db.Save(setting).Error
}
-
-// FindUsersWithDailyReport returns user IDs that have daily_report enabled.
-func (r *UserSettingRepository) FindUsersWithDailyReport() ([]uint, error) {
- var userIDs []uint
- if err := r.db.Model(&models.UserSetting{}).
- Where("daily_report = ?", true).
- Pluck("user_id", &userIDs).Error; err != nil {
- return nil, err
- }
- return userIDs, nil
-}
diff --git a/web/package.json b/web/package.json
index 6473f1d..05ed32f 100644
--- a/web/package.json
+++ b/web/package.json
@@ -6,7 +6,8 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "preview": "vite preview"
+ "preview": "vite preview",
+ "type-check": "vue-tsc --noEmit"
},
"dependencies": {
"@codemirror/lang-html": "^6.4.11",
diff --git a/web/src/api/sessions.ts b/web/src/api/sessions.ts
index 4beb6ab..42b42a5 100644
--- a/web/src/api/sessions.ts
+++ b/web/src/api/sessions.ts
@@ -5,6 +5,10 @@ export interface Session {
id: number
ip_address: string
user_agent: string
+ browser: string
+ os: string
+ device: string
+ label: string
current: boolean
created_at: string
expires_at: string
diff --git a/web/src/api/types.ts b/web/src/api/types.ts
index 5b81ba0..003b10f 100644
--- a/web/src/api/types.ts
+++ b/web/src/api/types.ts
@@ -653,6 +653,9 @@ export interface UserSettings {
api_key_expiry_days: number
bounce_auto_suppress: boolean
daily_report: boolean
+ notify_bounce_alerts: boolean
+ notify_api_key_expiry: boolean
+ notify_workspace_activity: boolean
created_at: string
updated_at: string
}
diff --git a/web/src/views/admin/UserDetail.vue b/web/src/views/admin/UserDetail.vue
index 92ec2e2..df44eeb 100644
--- a/web/src/views/admin/UserDetail.vue
+++ b/web/src/views/admin/UserDetail.vue
@@ -167,6 +167,13 @@ async function handleCancelDeletion() {
}
}
+// selectedPlanId reads a <select> change event's value as a plan id, or null
+// for the "no plan" option.
+function selectedPlanId(event: Event): number | null {
+ const value = (event.target as HTMLSelectElement).value
+ return Number(value) || null
+}
+
async function handleChangeUserPlan(planId: number | null) {
if (!metrics.value) return
changingUserPlan.value = true
@@ -442,7 +449,7 @@ function formatDate(date: string) {
style="max-width: 300px;"
:value="metrics.user.plan_id || ''"
:disabled="changingUserPlan"
- @change="handleChangeUserPlan(Number($event.target.value) || null)"
+ @change="handleChangeUserPlan(selectedPlanId($event))"
>
<option value="">No plan (use default)</option>
<option v-for="plan in plans" :key="plan.id" :value="plan.id">
@@ -480,7 +487,7 @@ function formatDate(date: string) {
class="form-select form-select-sm"
:value="ws.plan_id || ''"
:disabled="changingPlan === ws.id"
- @change="handleChangePlan(ws, Number($event.target.value) || null)"
+ @change="handleChangePlan(ws, selectedPlanId($event))"
>
<option value="">No plan (use default)</option>
<option v-for="plan in plans" :key="plan.id" :value="plan.id">
diff --git a/web/src/views/auth/Profile.vue b/web/src/views/auth/Profile.vue
index 4c37b33..f9bf54b 100644
--- a/web/src/views/auth/Profile.vue
+++ b/web/src/views/auth/Profile.vue
@@ -297,6 +297,18 @@ function parseUserAgent(ua: string): string {
return ua.slice(0, 30) + (ua.length > 30 ? '...' : '')
}
+// sessionLabel prefers the server-parsed label, falling back to the local
+// User-Agent parser for sessions created before the server enriched them.
+function sessionLabel(s: Session): string {
+ if (s.label && s.label !== 'Unknown device') return s.label
+ return parseUserAgent(s.user_agent)
+}
+
+// sessionDevice returns a short form-factor hint (e.g. "Mobile") when known.
+function sessionDevice(s: Session): string {
+ return s.device && s.device !== 'Unknown' ? s.device : ''
+}
+
function formatSessionDate(dateStr: string): string {
return new Date(dateStr).toLocaleDateString(undefined, {
year: 'numeric', month: 'short', day: 'numeric',
@@ -587,7 +599,8 @@ onMounted(() => { loadSessions() })
<div v-for="s in sessions" :key="s.id" class="session-item" :class="{ 'session-current': s.current }">
<div class="session-info">
<div class="session-browser">
- {{ parseUserAgent(s.user_agent) }}
+ {{ sessionLabel(s) }}
+ <span v-if="sessionDevice(s)" class="badge" style="margin-left: 6px">{{ sessionDevice(s) }}</span>
<span v-if="s.current" class="badge badge-success" style="margin-left: 6px">Current</span>
</div>
<div class="session-meta">
diff --git a/web/src/views/settings/Settings.vue b/web/src/views/settings/Settings.vue
index 0cca98d..1fc8cec 100644
--- a/web/src/views/settings/Settings.vue
+++ b/web/src/views/settings/Settings.vue
@@ -27,9 +27,30 @@ let savedClearTimer: ReturnType<typeof setTimeout> | null = null
const form = ref<Partial<UserSettings>>({
email_notifications: true,
notification_email: '',
- daily_report: false,
+ daily_report: true,
+ notify_bounce_alerts: true,
+ notify_api_key_expiry: true,
+ notify_workspace_activity: true,
})
+// Per-type notification toggles rendered under the master switch. Security
+// alerts (sign-in, 2FA, password, account deletion) are always on and shown
+// separately as informational.
+const notificationTypes: {
+ key: 'daily_report' | 'notify_bounce_alerts' | 'notify_api_key_expiry' | 'notify_workspace_activity'
+ label: string
+ hint: string
+}[] = [
+ { key: 'notify_bounce_alerts', label: 'Bounce & deliverability alerts', hint: 'Warn me when my bounce rate crosses the safe threshold.' },
+ { key: 'notify_api_key_expiry', label: 'API key expiry reminders', hint: 'Remind me before an API key expires.' },
+ { key: 'notify_workspace_activity', label: 'Workspace updates', hint: 'Notify me about role changes and workspace activity.' },
+ { key: 'daily_report', label: 'Daily report', hint: 'Receive a daily email summary of send statistics.' },
+]
+
+function toggleType(key: typeof notificationTypes[number]['key']) {
+ form.value[key] = !form.value[key]
+}
+
// Theme
const themeModes: { value: ThemeMode; label: string; icon: string }[] = [
{ value: 'light', label: 'Light', icon: 'sun' },
@@ -45,6 +66,9 @@ onMounted(async () => {
email_notifications: u.email_notifications,
notification_email: u.notification_email || '',
daily_report: u.daily_report,
+ notify_bounce_alerts: u.notify_bounce_alerts,
+ notify_api_key_expiry: u.notify_api_key_expiry,
+ notify_workspace_activity: u.notify_workspace_activity,
}
} catch {
notify.error('Failed to load settings')
@@ -130,7 +154,7 @@ async function autoSave() {
<div class="toggle-row">
<div>
<label class="toggle-label">Email Notifications</label>
- <span class="form-hint">Receive notifications on failures, bounces, etc.</span>
+ <span class="form-hint">Master switch for all notification emails below. Turn off to pause everything except security alerts.</span>
</div>
<button
:class="['toggle-btn', { active: form.email_notifications }]"
@@ -144,18 +168,38 @@ async function autoSave() {
<input v-model="form.notification_email" type="email" class="form-input" placeholder="Defaults to your login email" />
<span class="form-hint">Where to send notifications (can differ from your login email).</span>
</div>
- <div class="toggle-row" style="margin-top: 16px">
+
+ <div class="notif-divider"></div>
+ <p class="notif-group-title">Notification types</p>
+ <p class="form-hint" style="margin-top: -4px; margin-bottom: 8px">You receive all of these by default. Turn off any you don't want.</p>
+
+ <div
+ v-for="t in notificationTypes"
+ :key="t.key"
+ class="toggle-row notif-type-row"
+ :class="{ 'notif-disabled': !form.email_notifications }"
+ >
<div>
- <label class="toggle-label">Daily Report</label>
- <span class="form-hint">Receive a daily email summary of send statistics.</span>
+ <label class="toggle-label">{{ t.label }}</label>
+ <span class="form-hint">{{ t.hint }}</span>
</div>
<button
- :class="['toggle-btn', { active: form.daily_report }]"
- @click="form.daily_report = !form.daily_report"
+ :class="['toggle-btn', { active: form.email_notifications && form[t.key] }]"
+ :disabled="!form.email_notifications"
+ @click="toggleType(t.key)"
>
<span class="toggle-slider"></span>
</button>
</div>
+
+ <div class="notif-divider"></div>
+ <div class="toggle-row notif-type-row">
+ <div>
+ <label class="toggle-label">Security alerts</label>
+ <span class="form-hint">Sign-ins from new devices, 2FA changes, password changes, and account deletion. Always on to protect your account.</span>
+ </div>
+ <span class="badge badge-success notif-always-on">Always on</span>
+ </div>
</div>
</div>
@@ -247,6 +291,41 @@ async function autoSave() {
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}
+.toggle-btn:disabled {
+ cursor: not-allowed;
+ opacity: 0.5;
+}
+
+.notif-divider {
+ height: 1px;
+ background: var(--border-primary);
+ margin: 20px 0 16px;
+}
+
+.notif-group-title {
+ font-size: 13px;
+ font-weight: 600;
+ color: var(--text-primary);
+ margin: 0 0 4px;
+}
+
+.notif-type-row {
+ margin-top: 14px;
+}
+
+.notif-type-row:first-of-type {
+ margin-top: 0;
+}
+
+.notif-disabled .toggle-label,
+.notif-disabled .form-hint {
+ opacity: 0.6;
+}
+
+.notif-always-on {
+ flex-shrink: 0;
+}
+
.toggle-btn.active .toggle-slider {
transform: translateX(20px);
}
diff --git a/web/tsconfig.node.json b/web/tsconfig.node.json
index 257785d..252b9fc 100644
--- a/web/tsconfig.node.json
+++ b/web/tsconfig.node.json
@@ -1,11 +1,13 @@
{
"compilerOptions": {
+ "composite": true,
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
+ "outDir": "./node_modules/.tmp/node-build",
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
- "strict": true,
- "noEmit": true
+ "strict": true
},
"include": ["vite.config.ts"]
}