diff --git a/.env.selfhost.example b/.env.selfhost.example index 976d7782..2edfff36 100644 --- a/.env.selfhost.example +++ b/.env.selfhost.example @@ -41,5 +41,10 @@ AUTH_EMAIL_RATE_LIMIT=5 # Optional: prefix all Redis keys (useful for shared Redis with ACL isolation) # REDIS_KEY_PREFIX="" +# Optional: clear stored email content (text, html, attachments, headers) from +# the database after this many days. Runs daily at midnight UTC. Leave unset to +# keep email content indefinitely. +# EMAIL_CLEANUP_DAYS=30 + # used to send important error notification - optional DISCORD_WEBHOOK_URL="" diff --git a/apps/docs/self-hosting/overview.mdx b/apps/docs/self-hosting/overview.mdx index 0a44b56d..cadffa87 100644 --- a/apps/docs/self-hosting/overview.mdx +++ b/apps/docs/self-hosting/overview.mdx @@ -80,6 +80,16 @@ Add the following environment variables. NEXTAUTH_SECRET="" ``` + + + By default, stored email content stays in the database forever. To bound database growth, set `EMAIL_CLEANUP_DAYS` to a positive number of days. A daily job (midnight UTC) then clears the `text`, `html`, `attachments` and `headers` values for emails older than the cutoff. Delivery status and event history are kept. + +```env +EMAIL_CLEANUP_DAYS=30 +``` + +Leave it unset to keep email content indefinitely. + diff --git a/apps/web/src/server/jobs/cleanup-email-bodies.ts b/apps/web/src/server/jobs/cleanup-email-bodies.ts index a8020c96..cb000bc4 100644 --- a/apps/web/src/server/jobs/cleanup-email-bodies.ts +++ b/apps/web/src/server/jobs/cleanup-email-bodies.ts @@ -37,11 +37,15 @@ if (isSelfHosted() && isEmailCleanupEnabled()) { OR: [ {text: {not: null}}, {html: {not: null}}, + {attachments: {not: null}}, + {headers: {not: null}}, ], }, data: { text: null, html: null, + attachments: null, + headers: null, }, });