tls-options module provides default TLS/SSL configuration for secure SMTP connections, including pre-generated localhost certificates for development and production-ready security settings.
Usage
getTLSOptions(opts)
Merges custom TLS options with secure defaults.Custom TLS options to override defaults. Accepts all standard Node.js
tls.createServer options.Object - Merged TLS configuration object
lib/tls-options.js
Default TLS Options
The module provides secure defaults suitable for SMTP servers:Security Settings
Server chooses cipher suite order instead of client preference, improving security by ensuring strong ciphers are preferred
Whether to request OCSP stapling from clients (disabled by default for compatibility)
Session ID context for TLS session resumption. Automatically generated as SHA-1 hash of process arguments:
Minimum TLS version accepted. Set to
TLSv1 for compatibility with legacy SMTP clients.Default Certificates
The module includes pre-generated RSA certificates for localhost testing.Private Key
RSA private key in PEM format (2048-bit)
Certificate
X.509 certificate in PEM format for
localhost- Subject: localhost
- Valid from: 2015-02-12
- Valid to: 2025-02-09
- Key size: 2048-bit RSA
Production Configuration
For production use, always provide your own certificates:Common TLS Options
You can override any Node.js TLS option:Certificate Options
Private key in PEM format. Can be an array of keys for multiple certificates.
Certificate chain in PEM format. Can be an array for multiple certificates.
Certificate authority bundle for client certificate validation
PFX or PKCS12 encoded private key and certificate chain
Passphrase for the private key or PFX file
Security Options
Minimum TLS version:
TLSv1, TLSv1.1, TLSv1.2, or TLSv1.3Maximum TLS version:
TLSv1.3, TLSv1.2, etc.Cipher suite specification in OpenSSL format
If true, server’s cipher preference is used instead of client’s
ECDH curve name for key exchange (default: auto)
Client Authentication
Request client certificate during handshake
Reject clients without valid certificates (requires
requestCert: true)Custom function to verify server identity
Session Management
Unique identifier for TLS session cache (max 32 characters)
Lifetime of TLS sessions in seconds
48-byte buffer for TLS session ticket encryption
STARTTLS vs Direct TLS
The SMTP server supports both STARTTLS (opportunistic TLS) and direct TLS (implicit TLS):STARTTLS (Port 587/25)
Direct TLS (Port 465)
STARTTLS on port 587 is the modern standard for email submission. Direct TLS on port 465 is legacy but still widely supported.
Certificate Generation
For development, generate self-signed certificates:Let’s Encrypt Integration
For free production certificates, use Let’s Encrypt with automatic renewal:Remember to reload certificates when Let’s Encrypt renews them (typically every 90 days).
SNI Support
For multi-domain support using Server Name Indication (SNI):Security Best Practices
- Never use default certificates in production
- Use TLSv1.2 or higher for modern security:
- Configure strong cipher suites:
- Enable cipher order preference:
- Keep certificates updated - automate renewal with Let’s Encrypt
- Use certificate pinning for critical connections
- Monitor certificate expiration dates