Skip to content

Environment Variables

Complete reference of all environment variables used to configure Relate Mail services.

Database

VariableDefaultDescription
ConnectionStrings__DefaultConnection(required)PostgreSQL connection string. Format: Host=hostname;Port=5432;Database=relate_mail;Username=user;Password=pass

All services (API, SMTP, POP3, IMAP) require this variable. In Docker Compose deployments, it is constructed automatically from the POSTGRES_* variables.

Example:

bash
ConnectionStrings__DefaultConnection="Host=postgres;Port=5432;Database=relate_mail;Username=postgres;Password=my-secret"

Authentication

VariableDefaultDescription
Oidc__Authority(empty)OIDC provider URL (e.g., https://auth.example.com). When empty, the system runs in development mode without OIDC authentication.
Oidc__Audience(empty)Expected audience claim in OIDC tokens. Typically the API's client ID or URL.
Jwt__DevelopmentKey(empty)Symmetric key for signing development JWT tokens. Only used when Oidc__Authority is not set. Must be at least 32 characters for HS256.

Development Mode

When Oidc__Authority is empty, authentication operates in development mode:

  • The API generates and validates JWTs using the Jwt__DevelopmentKey symmetric key
  • No external identity provider is required
  • The web frontend skips the OIDC login redirect

For production, always configure a real OIDC provider.

SMTP Server

VariableDefaultDescription
Smtp__EnabledtrueEnable or disable the SMTP server
Smtp__ServerNamelocalhostSMTP server hostname (used in the EHLO greeting)
Smtp__Port587SMTP STARTTLS submission port
Smtp__SecurePort465SMTP implicit TLS submission port
Smtp__RequireAuthenticationtrueRequire authentication on submission ports (587, 465)
Smtp__CertificatePath(empty)Path to a PFX/PKCS12 TLS certificate file
Smtp__CertificatePassword(empty)Password for the TLS certificate file
Smtp__MaxAttachmentSizeBytes26214400Maximum attachment size (default: 25 MB)
Smtp__MaxMessageSizeBytes52428800Maximum total message size (default: 50 MB)

MX Endpoint (Inbound Internet Mail)

VariableDefaultDescription
Smtp__Mx__EnabledfalseEnable the MX endpoint on port 25 for receiving internet mail
Smtp__Mx__Port25MX endpoint port
Smtp__Mx__HostedDomains__0(empty)First hosted domain (e.g., example.com). Add more with __1, __2, etc.
Smtp__Mx__ValidateRecipientstrueCheck that the recipient email address exists in the database before accepting mail

The MX endpoint accepts unauthenticated inbound mail only for the configured hosted domains. It is not an open relay -- mail addressed to domains not listed in HostedDomains is rejected.

Multiple hosted domains:

bash
Smtp__Mx__HostedDomains__0=example.com
Smtp__Mx__HostedDomains__1=mail.example.com
Smtp__Mx__HostedDomains__2=another-domain.org

POP3 Server

VariableDefaultDescription
Pop3__EnabledtrueEnable or disable the POP3 server
Pop3__ServerNamelocalhostPOP3 server hostname
Pop3__Port110POP3 plaintext/STARTTLS port
Pop3__SecurePort995POP3 implicit TLS (POP3S) port
Pop3__RequireAuthenticationtrueRequire authentication for POP3 connections

IMAP Server

VariableDefaultDescription
Imap__EnabledtrueEnable or disable the IMAP server
Imap__ServerNamelocalhostIMAP server hostname
Imap__Port143IMAP plaintext/STARTTLS port
Imap__SecurePort993IMAP implicit TLS (IMAPS) port
Imap__RequireAuthenticationtrueRequire authentication for IMAP connections

Outbound Mail

VariableDefaultDescription
OutboundMail__EnabledfalseEnable outbound email delivery
OutboundMail__RelayHost(empty)SMTP relay server hostname. When empty, delivers directly via MX lookup.
OutboundMail__RelayPort587Relay server port
OutboundMail__RelayUsername(empty)Relay server authentication username
OutboundMail__RelayPassword(empty)Relay server authentication password
OutboundMail__RelayUseTlstrueUse TLS when connecting to the relay server
OutboundMail__MaxConcurrency5Maximum concurrent outbound delivery connections
OutboundMail__MaxRetries10Maximum delivery retry attempts before marking as failed
OutboundMail__RetryBaseDelaySeconds60Base delay between retries (increases exponentially)
OutboundMail__QueuePollingIntervalSeconds15How often to check the outbound queue for pending messages
OutboundMail__SmtpTimeoutSeconds30Timeout for outbound SMTP connections
OutboundMail__SenderDomainlocalhostDomain used in the MAIL FROM envelope and Message-Id header

Direct Delivery vs. Relay

When RelayHost is empty, the system performs direct MX delivery by looking up the recipient domain's MX records and connecting directly. This requires:

  • Port 25 outbound access (many cloud providers block this by default)
  • Proper SPF, DKIM, and DMARC records for your sender domain

When RelayHost is set, all outbound mail is sent through the specified relay server (e.g., Amazon SES, SendGrid, Mailgun, or your ISP's SMTP server). This is the recommended approach for most deployments.

Security

VariableDefaultDescription
Security__AuthenticationSalt(empty)Additional salt for API key hashing (combined with BCrypt)
Security__RateLimit__MaxFailedAttempts5Maximum failed authentication attempts before lockout
Security__RateLimit__LockoutWindowMinutes15Duration of authentication lockout
Security__RateLimit__BaseBackoffDelaySeconds1Base delay for exponential backoff on failed auth
Security__RateLimit__MaxBackoffDelaySeconds30Maximum backoff delay

CORS

VariableDefaultDescription
Cors__AllowedOrigins__0http://localhost:5173First allowed CORS origin
Cors__AllowedOrigins__1http://localhost:5492Second allowed CORS origin

Add more origins using sequential indices (__2, __3, etc.). In production, set these to your actual frontend URLs:

bash
Cors__AllowedOrigins__0=https://mail.example.com
Cors__AllowedOrigins__1=https://app.example.com

Internal Communication

VariableDefaultDescription
Internal__ApiKey(empty)Pre-shared API key for service-to-service communication. The SMTP server uses this to notify the API of new incoming messages.
Api__BaseUrl(empty)Internal URL of the API server. Used by protocol hosts to send notifications. In Docker: http://api:8080.

The internal API key should be a long, random string. It is used by the SMTP, POP3, and IMAP hosts to authenticate with the API's internal notification endpoint.

Observability

VariableDefaultDescription
Otel__Endpoint(null)OpenTelemetry collector endpoint URL. When set, the API exports traces and metrics.

Logging

VariableDefaultDescription
Logging__LogLevel__DefaultInformationDefault log level
Logging__LogLevel__Microsoft.AspNetCoreWarningASP.NET Core framework log level

Standard .NET log levels: Trace, Debug, Information, Warning, Error, Critical.

Health Checks

VariableDefaultDescription
HealthCheck__Url(varies)HTTP URL for the internal health check endpoint. Set automatically in Docker images: SMTP=http://+:8081, POP3=http://+:8082, IMAP=http://+:8083.

Frontend (Build-Time)

These variables are used when building the web frontend outside of Docker (e.g., for local development). In Docker deployments, the frontend reads configuration from the /api/config runtime endpoint instead.

VariableDefaultDescription
VITE_API_URL/apiBase URL for API requests. Defaults to /api which is proxied by Vite in development.
VITE_OIDC_AUTHORITY(empty)OIDC provider URL for the frontend login flow
VITE_OIDC_CLIENT_ID(empty)OIDC client ID for the frontend application

ASP.NET Core

VariableDefaultDescription
ASPNETCORE_ENVIRONMENTProductionRuntime environment. Set to Development for auto-migration and detailed errors.
ASPNETCORE_URLShttp://+:8080URL bindings for the API server (set in Dockerfile)
AllowedHostslocalhostSemicolon-separated list of allowed Host header values. Set to * for production behind a reverse proxy.

Complete Example

A production .env file for Docker Compose:

env
# Database
POSTGRES_PASSWORD=strong-random-password-here
POSTGRES_USER=postgres
POSTGRES_DB=relate_mail

# Authentication
OIDC_AUTHORITY=https://auth.example.com
OIDC_AUDIENCE=relate-mail-api

# SMTP
SMTP_SERVER_NAME=mail.example.com
SMTP_MX_ENABLED=true
SMTP_MX_HOSTED_DOMAIN=example.com
SMTP_MX_VALIDATE_RECIPIENTS=true

# Internal communication
INTERNAL_API_KEY=long-random-string-for-service-communication

# Outbound mail (via relay)
OutboundMail__Enabled=true
OutboundMail__RelayHost=smtp.sendgrid.net
OutboundMail__RelayPort=587
OutboundMail__RelayUsername=apikey
OutboundMail__RelayPassword=SG.your-sendgrid-api-key
OutboundMail__SenderDomain=example.com

Released under the MIT License.