Skip to content

Spam Analysis

The Gateway integrates with Rspamd to provide spam analysis for incoming emails. When enabled, each email is analyzed and scored, with results included in the email metadata.

Spam analysis is an optional feature that:

  • Analyzes emails using Rspamd’s detection engine
  • Returns spam scores and triggered rules (symbols)
  • Provides actionable recommendations (reject, add header, etc.)
  • Operates at both global and per-inbox levels
  • Rspamd service running and accessible
  • Gateway configured to connect to Rspamd

The simplest way to enable spam analysis is to run Rspamd alongside the gateway:

services:
gateway:
image: vaultsandbox/gateway:latest
container_name: vaultsandbox-gateway
restart: unless-stopped
ports:
- '25:25' # SMTP
- '80:80' # HTTP (ACME challenges)
- '443:443' # HTTPS (Web UI + API)
environment:
VSB_VSX_DNS_ENABLED: 'true'
VSB_ENCRYPTION_ENABLED: 'enabled'
# Spam Analysis - Rspamd integration
VSB_SPAM_ANALYSIS_ENABLED: 'true'
VSB_RSPAMD_URL: 'http://rspamd:11333'
VSB_RSPAMD_TIMEOUT_MS: '5000'
# VSB_RSPAMD_PASSWORD: 'optional-password' # Only if Rspamd has auth enabled
VSB_SPAM_ANALYSIS_INBOX_DEFAULT: 'true'
volumes:
- gateway-data:/app/data
depends_on:
- rspamd
rspamd:
image: rspamd/rspamd:latest
container_name: rspamd
restart: unless-stopped
# Web UI only on localhost (not exposed publicly)
ports:
- '127.0.0.1:11334:11334'
volumes:
- rspamd-data:/var/lib/rspamd
volumes:
gateway-data:
rspamd-data:
VariableDefaultDescription
VSB_SPAM_ANALYSIS_ENABLEDfalseEnable spam analysis globally
VSB_RSPAMD_URLhttp://localhost:11333Rspamd worker API URL
VSB_RSPAMD_TIMEOUT_MS5000Request timeout in milliseconds
VSB_RSPAMD_PASSWORDPassword for Rspamd authentication (optional)
VSB_SPAM_ANALYSIS_INBOX_DEFAULTtrueDefault spam analysis setting for new inboxes

Description: Master switch to enable spam analysis. When false, no emails are analyzed regardless of per-inbox settings.

Default: false

Example:

Terminal window
VSB_SPAM_ANALYSIS_ENABLED=true

Description: Base URL for the Rspamd worker API. The gateway sends emails to the /checkv2 endpoint.

Default: http://localhost:11333

Example:

Terminal window
VSB_RSPAMD_URL=http://rspamd:11333

Description: Maximum time to wait for Rspamd response in milliseconds. If exceeded, the analysis returns status: 'error' with timeout information.

Default: 5000 (5 seconds)

Example:

Terminal window
VSB_RSPAMD_TIMEOUT_MS=10000 # 10 seconds

Description: Password for Rspamd controller authentication. Only required if Rspamd is configured with authentication enabled.

Default: Not set (no authentication)

Example:

Terminal window
VSB_RSPAMD_PASSWORD=your-rspamd-password

Description: Default spam analysis setting for newly created inboxes when clients don’t specify a preference.

Default: true (spam analysis enabled for new inboxes)

Example:

Terminal window
VSB_SPAM_ANALYSIS_INBOX_DEFAULT=false # Disable by default for new inboxes

Spam analysis can be enabled or disabled per inbox, allowing fine-grained control over which inboxes receive spam analysis.

When creating an inbox via the API, specify the spamAnalysis parameter:

Terminal window
curl -X POST https://your-gateway/api/inboxes \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"spamAnalysis": true
}'

If spamAnalysis is not specified, it defaults to the value of VSB_SPAM_ANALYSIS_INBOX_DEFAULT.

Spam analysis follows a three-level hierarchy:

  1. Global Level (VSB_SPAM_ANALYSIS_ENABLED)

    • If false, spam analysis is disabled for ALL emails
    • If true, proceeds to inbox-level check
  2. Per-Inbox Level (spamAnalysis field on inbox)

    • If inbox has spamAnalysis: false, analysis is skipped for that inbox
    • If inbox has spamAnalysis: true, analysis proceeds
  3. Result: Analysis only runs when both global and inbox settings are enabled

When spam analysis is performed, the results are included in the email response under the spamAnalysis field:

{
"id": "email-id",
"from": "sender@example.com",
"to": ["recipient@your-domain.com"],
"subject": "Test Email",
"spamAnalysis": {
"status": "analyzed",
"score": 5.2,
"requiredScore": 15.0,
"action": "add header",
"isSpam": false,
"symbols": [
{
"name": "BAYES_SPAM",
"score": 3.5,
"description": "Bayes spam probability",
"options": ["99.98%"]
},
{
"name": "MISSING_MID",
"score": 0.5,
"description": "Message-ID header is missing"
}
],
"processingTimeMs": 45
}
}
StatusDescription
analyzedEmail was successfully analyzed
skippedAnalysis was skipped (disabled globally or per-inbox)
errorAnalysis failed (timeout, connection error, etc.)

Rspamd returns an action recommendation based on the spam score:

ActionDescription
no actionEmail is likely legitimate
greylistTemporary rejection recommended (greylisting)
add headerAdd spam header but deliver
rewrite subjectModify subject line to indicate spam
soft rejectTemporary rejection
rejectPermanently reject the email

Symbols represent the individual rules that triggered during analysis. Each symbol includes:

  • name: Rule identifier (e.g., BAYES_SPAM, DKIM_SIGNED)
  • score: Score contribution (positive = spam, negative = ham)
  • description: Human-readable explanation (optional)
  • options: Additional context or parameters (optional)

When spam analysis is enabled, the gateway tracks the following metrics under the spam object in the /api/metrics response:

MetricDescription
spam.analyzed_totalTotal emails analyzed
spam.processing_time_msTotal processing time in milliseconds
spam.spam_detected_totalEmails classified as spam
spam.errors_totalAnalysis errors
spam.skipped_totalSkipped analyses

The default Rspamd image works out of the box. For custom configuration, mount a volume with your Rspamd config files:

rspamd:
image: rspamd/rspamd:latest
volumes:
- rspamd-data:/var/lib/rspamd
- ./rspamd/local.d:/etc/rspamd/local.d:ro

The Rspamd web interface runs on port 11334. For security, only expose it locally:

rspamd:
ports:
- '127.0.0.1:11334:11334' # Only accessible from localhost

Then access it at http://localhost:11334 in your browser.

To enable authentication for Rspamd:

  1. Generate a password hash:

    Terminal window
    docker run --rm rspamd/rspamd rspamadm pw -p your-password
  2. Add to local.d/worker-controller.inc:

    password = "$2$generated-hash-here";
  3. Set VSB_RSPAMD_PASSWORD in the gateway:

    Terminal window
    VSB_RSPAMD_PASSWORD=your-password

Check if Rspamd is running and accessible:

Terminal window
# Test Rspamd connectivity
curl -v http://rspamd:11333/ping
# Check Rspamd logs
docker logs rspamd

If analysis frequently times out:

  1. Increase the timeout: VSB_RSPAMD_TIMEOUT_MS=10000
  2. Check Rspamd resource usage
  3. Ensure network connectivity between containers

Verify configuration:

  1. VSB_SPAM_ANALYSIS_ENABLED=true at global level
  2. Inbox has spamAnalysis: true (or VSB_SPAM_ANALYSIS_INBOX_DEFAULT=true)
  3. Gateway is running in local mode (spam analysis not available in backend mode)