Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.selfhost.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
10 changes: 10 additions & 0 deletions apps/docs/self-hosting/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ Add the following environment variables.
NEXTAUTH_SECRET="<your-usesend-secret>"
```

</Step>
<Step title="Email content retention (optional)">
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.

</Step>
</Steps>

Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/server/jobs/cleanup-email-bodies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});

Expand Down