← Back to Pull requests

Document SMTP email setup for Docker Compose #4372

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 21, 2026 02:52 UTC
Author

Closes #4364

Fork pre-flight: jaysbeekay/sure#521, from the same branch and commit. Its CI runs and reviews, and the fork issue with the plan (jaysbeekay/sure#502), are there.

Problem

docs/hosting/docker.md has no section on sending email. A self-hoster has to work out the setup from the code, and it fails silently in three ways:

  • The settings never reach the containers. compose.example.yml passes only the keys listed in its x-rails-env anchor, and has no env_file, so values set only in .env are dropped.

  • The worker lacks them. Mail goes through Sidekiq (deliver_later_queue_name = :high_priority, config/environments/production.rb:77), not web.

  • Mail goes out from sender@sure.local (app/mailers/application_mailer.rb:3) and the relay rejects it.
  • Change

    Docs only. A new "Sending email (SMTP)" section in docs/hosting/docker.md, after "Using HTTPS":

  • Which emails a self-hosted instance sends, and when: password resets, email-change confirmation (only with Require email confirmation on), rule notifications and the PDF import follow-up. Invitations are never emailed when self-hosted, so the section says to copy the link from Settings > Profile Info.

  • A table of each variable, what it does, and the app's default when it is not set.

  • The exact "true" comparison for SMTP_TLS_ENABLED and SMTP_TLS_SKIP_VERIFY, the sender@sure.local fallback, and that the worker sends mail.

  • How values reach the containers: add the keys to the x-rails-env anchor, which both web and worker merge. Includes a snippet and the matching .env lines. A sentence under the snippet says its Compose defaults (port 465, TLS from the start) differ from the app's own in the table, and the .env example carries commented SMTP_PORT="587" / SMTP_TLS_ENABLED="false" lines for STARTTLS.

  • A listed key with no value in .env reaches the app as an empty string, not as unset. An empty EMAIL_SENDER replaces the fallback, and an empty SMTP_USERNAME still makes the app attempt SMTP AUTH. The section tells readers to set every listed key and leave out the login keys for a relay that needs no login.

  • #2811 is named as an open PR that would make the anchor step unnecessary.

  • Apply changes with docker compose up -d; docker compose restart keeps the old environment.

  • A check that does not print the password.
  • Verification

    Variable names, each checked against the code at 7917bc1e4:

    | Variable | Read at |
    |---|---|
    | APP_DOMAIN | config/environments/production.rb:78 |
    | SMTP_ADDRESS | config/environments/production.rb:81 |
    | SMTP_PORT | config/environments/production.rb:82 |
    | SMTP_USERNAME | config/environments/production.rb:83 |
    | SMTP_PASSWORD | config/environments/production.rb:84 |
    | SMTP_TLS_ENABLED | config/environments/production.rb:85 (== "true") |
    | SMTP_TLS_SKIP_VERIFY | config/environments/production.rb:86 (== "true") |
    | SSL_CA_FILE | config/environments/production.rb:87 |
    | EMAIL_SENDER | app/mailers/application_mailer.rb:3 (ENV.fetch, fallback sender@sure.local) |

    Emails, each checked against the code at 7917bc1e4:

    | Email | Sent at | Condition on a self-hosted instance |
    |---|---|---|
    | Password reset | app/controllers/password_resets_controller.rb:20 | ensure_password_resets_enabled (:49, AuthConfig.password_features_enabled?) |
    | Email-change confirmation | app/models/user.rb:138 | skipped when self_hosted? && !Setting.require_email_confirmation (user.rb:134), the "Require email confirmation" toggle under Self-Hosting |
    | Rule notification | app/jobs/rule_email_notification_job.rb:15 | a rule with the "Send email notification" action |
    | PDF import follow-up | app/models/pdf_import.rb:391, from app/jobs/process_pdf_job.rb:36 | none |
    | Invitation | app/controllers/invitations_controller.rb:27 | never: deliver_later unless self_hosted? |

    The settings hash keys are address, port, user_name and tls (production.rb:81-85), so the check command's slice(:address, :port, :user_name, :tls) matches them and leaves out password.

    Defaults and TLS modes were checked against the locked gems (mail 2.9.1, net-smtp 0.5.1), building the session from the same settings hash:

  • SMTP_PORT unset: port 25.

  • SMTP_TLS_ENABLED=true: implicit TLS, no STARTTLS.

  • SMTP_TLS_ENABLED unset, True or 1: plain connection with STARTTLS auto.

  • ENV.fetch("EMAIL_SENDER", "sender@sure.local") returns "" when the variable is set but empty.

  • Net::SMTP authenticates whenever the user name is truthy, which includes "".
  • Compose snippet: merged into the x-rails-env anchor of a copy of compose.example.yml and run through docker compose config (Compose v5.6.0). Exit code 0. With the .env from the section, web and worker both resolve all seven keys. With no .env, both get "" for each key that has no :- default, and SMTP_PORT: "465" and SMTP_TLS_ENABLED: "true" from the defaults.

    The section uses only example.com hosts and addresses, apart from the code's own sender@sure.local.

  • bin/rails test: 12474 runs, 0 failures, 0 errors, 36 skips. Markdown only, so rubocop, erb_lint, Biome and brakeman have nothing to check.
  • <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    Documentation
    Added guidance for configuring SMTP email delivery in self-hosted deployments, including which email types are sent and that invitations are not emailed.
    Documented SMTP settings, defaults, TLS options, and how empty values differ from unset values.
    Included Docker Compose examples, instructions for mounting a custom CA certificate and recreating containers, and a way to review worker settings without displaying the password.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jaysbeekay Review duration: 1725m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.52) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #4372"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.7% · Safe to merge
    29.7%