Deploying DavMail
DavMail is a gateway application that provides standard email and calendar protocols (POP, IMAP, SMTP, CalDAV, CardDAV, and LDAP) for Microsoft Exchange and Office 365 servers. If you’re using email clients like Thunderbird, Apple Mail, or any mobile device that doesn’t natively support Exchange Web Services (EWS), DavMail acts as a translator between these standard protocols and Exchange’s proprietary APIs. This means you can access your corporate Exchange mailbox using any standard email client without being locked into Microsoft’s ecosystem.
What makes DavMail particularly valuable is its cross-platform compatibility and protocol versatility. It runs as a local or server-based gateway, handling authentication with Exchange servers while presenting standard protocol interfaces to your email clients. Whether you’re dealing with on-premises Exchange servers or Office 365 cloud services, DavMail provides a unified interface that works with virtually any email client. The gateway also handles complex authentication scenarios including OAuth2 for Office 365, making it possible to use modern security features while maintaining compatibility with older email clients.
Why Deploy DavMail on Klutch.sh?
Deploying DavMail on Klutch.sh offers several advantages for hosting your email gateway:
- Automatic Docker Detection: Klutch.sh recognizes your Dockerfile and handles containerization without manual configuration
- Multi-Protocol Support: Run all email protocols (POP, IMAP, SMTP) and calendar protocols (CalDAV, CardDAV) from a single deployment
- Persistent Storage: Built-in volume management ensures your configuration and cached credentials persist across deployments
- TCP Traffic Routing: Access multiple protocol ports through Klutch.sh’s TCP routing on port 8000
- Environment Management: Securely configure Exchange credentials, OAuth tokens, and protocol settings through environment variables
- Always-On Availability: Keep your email gateway running 24/7 without managing local infrastructure
- SSL/TLS Termination: Secure connections to your gateway with automatic certificate management
Prerequisites
Before deploying DavMail to Klutch.sh, ensure you have:
- A Klutch.sh account (sign up here)
- A GitHub account with a repository for your DavMail deployment
- Basic understanding of Docker and containerization
- Access to a Microsoft Exchange server or Office 365 account
- Your Exchange server URL (OWA URL for on-premises or Office 365 URL)
- Exchange credentials (username and password, or OAuth2 setup for Office 365)
- Git installed on your local development machine
- Familiarity with email protocols (IMAP, SMTP, CalDAV)
Understanding DavMail Architecture
DavMail follows a gateway architecture designed to bridge standard email protocols with Exchange services:
Core Components
Java Application Server
DavMail is built in Java, making it truly cross-platform and capable of running anywhere the JVM is available. The application listens on multiple ports simultaneously, each handling a different protocol (IMAP, POP, SMTP, CalDAV, CardDAV, LDAP). The Java runtime provides robust multi-threading capabilities, allowing DavMail to handle multiple concurrent client connections efficiently.
Protocol Translators
Each protocol has a dedicated translator module that converts standard protocol commands into Exchange Web Services (EWS) or Outlook Web Access (OWA) API calls. For example, when your email client sends an IMAP FETCH command, DavMail translates it into the appropriate EWS request, retrieves the data from Exchange, and formats the response according to IMAP specifications.
Exchange Connectivity Layer
DavMail supports multiple Exchange connection modes:
- EWS (Exchange Web Services): Modern XML-based protocol for Exchange 2007 and newer
- OWA (Outlook Web Access): HTTP-based access for older Exchange versions
- Office 365: Cloud-based Exchange with OAuth2 authentication support
The gateway automatically handles session management, authentication, and connection pooling with the Exchange server.
Authentication Handler
DavMail manages authentication in two stages. First, it authenticates your email client connection (can be configured with separate credentials or pass-through). Second, it maintains an authenticated session with the Exchange server. For Office 365, DavMail can handle OAuth2 token acquisition and renewal, eliminating the need for app-specific passwords.
Protocol Listeners
Each protocol runs on its own configurable port:
- IMAP: Port 1143 (typically, default would be 143 but often changed to avoid conflicts)
- POP: Port 1110
- SMTP: Port 1025
- CalDAV: Port 1080 (HTTP endpoint)
- CardDAV: Port 1080 (same HTTP endpoint as CalDAV)
- LDAP: Port 1389
These ports are internal to the container and can be exposed through Klutch.sh’s TCP routing.
Configuration System
DavMail uses a properties file for configuration, supporting both GUI-based setup and headless server mode. Configuration options include Exchange server URLs, authentication settings, protocol port assignments, SSL/TLS settings, and logging preferences.
Request Flow
- Email client connects to DavMail on protocol-specific port (IMAP, SMTP, etc.)
- DavMail authenticates the client connection
- Client sends protocol command (e.g., IMAP SELECT command to open a folder)
- DavMail translates command to Exchange API call
- Exchange server processes request and returns data
- DavMail formats Exchange response according to protocol specifications
- Response is sent back to email client
- Session state is maintained for subsequent requests
- Logs capture protocol interactions for troubleshooting
Storage Requirements
DavMail requires persistent storage for:
- Configuration Files: davmail.properties and authentication settings
- Log Files: Protocol traces and error logs
- Token Cache: OAuth2 tokens for Office 365 (when applicable)
- SSL Certificates: Custom certificates if not using default
A typical deployment needs 100MB-500MB for configuration and logs. Storage grows based on log retention policies.
Installation and Setup
Let’s walk through setting up DavMail for deployment on Klutch.sh.
Step 1: Create the Project Structure
First, create a new directory for your DavMail deployment:
mkdir davmail-deploymentcd davmail-deploymentgit initStep 2: Create Configuration File
Create a davmail.properties file with your Exchange configuration:
# DavMail Configuration
# Exchange Server Settings# For Office 365, use: https://outlook.office365.com/EWS/Exchange.asmx# For on-premises Exchange, use your OWA URLdavmail.url=https://outlook.office365.com/EWS/Exchange.asmx
# Exchange mode: EWS, WebDav, or autodavmail.mode=EWS
# Protocol Portsdavmail.imapPort=1143davmail.popPort=1110davmail.smtpPort=1025davmail.caldavPort=1080davmail.ldapPort=1389
# Bind all protocols to all interfaces (required for Docker)davmail.bindAddress=0.0.0.0
# Enable all protocolsdavmail.enableImap=truedavmail.enablePop=truedavmail.enableSmtp=truedavmail.enableCaldav=truedavmail.enableLdap=true
# Authentication settings# Leave empty for client-provided credentialsdavmail.username=davmail.password=
# OAuth settings for Office 365davmail.oauth.clientId=d3590ed6-52b3-4102-aeff-aad2292ab01cdavmail.oauth.redirectUri=http://localhost:8080/
# SSL/TLS Settingsdavmail.ssl.nosecurepop=falsedavmail.ssl.nosecureimap=falsedavmail.ssl.nosecuresmtp=falsedavmail.ssl.nosecurecaldav=falsedavmail.ssl.nosecureldap=false
# Disable GUI mode for headless operationdavmail.server=truedavmail.disableGuiNotifications=truedavmail.showStartupBanner=false
# Loggingdavmail.logFilePath=/var/log/davmail/davmail.logFileSize=1MBdavmail.rootLoggingLevel=INFO
# Timeouts (in seconds)davmail.keepDelay=300davmail.sentKeepDelay=3600
# Calendar and contact settingsdavmail.caldavPastDelay=90davmail.caldavAutoSchedule=truedavmail.forceActiveSyncUpdate=false
# IMAP folder mappingsdavmail.defaultDomain=davmail.imapAutoExpunge=truedavmail.smtpSaveInSent=true
# Connection poolingdavmail.keepAlive=truedavmail.enableKeepalive=trueFor Office 365 with OAuth2, use the default client ID provided or register your own application in Azure AD.
Step 3: Create the Dockerfile
Create a Dockerfile in the root directory:
FROM eclipse-temurin:17-jre-alpine
# Set environment variablesENV DAVMAIL_VERSION=6.2.1 \ DAVMAIL_HOME=/opt/davmail \ DAVMAIL_CONF=/etc/davmail \ DAVMAIL_LOG=/var/log/davmail
# Install dependenciesRUN apk add --no-cache \ bash \ curl \ ca-certificates \ tzdata
# Create directoriesRUN mkdir -p ${DAVMAIL_HOME} ${DAVMAIL_CONF} ${DAVMAIL_LOG}
# Download and install DavMailRUN curl -L "https://sourceforge.net/projects/davmail/files/davmail/${DAVMAIL_VERSION}/davmail-${DAVMAIL_VERSION}.zip/download" \ -o /tmp/davmail.zip && \ unzip /tmp/davmail.zip -d /tmp && \ mv /tmp/davmail-${DAVMAIL_VERSION}/* ${DAVMAIL_HOME}/ && \ rm -rf /tmp/davmail* && \ chmod +x ${DAVMAIL_HOME}/davmail
# Create davmail userRUN addgroup -g 1000 davmail && \ adduser -D -u 1000 -G davmail davmail && \ chown -R davmail:davmail ${DAVMAIL_HOME} ${DAVMAIL_CONF} ${DAVMAIL_LOG}
# Copy configurationCOPY --chown=davmail:davmail davmail.properties ${DAVMAIL_CONF}/
# Switch to davmail userUSER davmail
# Expose protocol portsEXPOSE 1143 1110 1025 1080 1389
# Health checkHEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \ CMD nc -z localhost 1143 || exit 1
# Set working directoryWORKDIR ${DAVMAIL_HOME}
# Start DavMailCMD ["./davmail", "/etc/davmail/davmail.properties"]Step 4: Create Startup Script (Alternative Configuration Method)
Create a start-davmail.sh script for dynamic configuration:
#!/bin/bash
CONFIG_FILE="/etc/davmail/davmail.properties"
# Update configuration from environment variables if providedif [ ! -z "$EXCHANGE_URL" ]; then sed -i "s|davmail.url=.*|davmail.url=${EXCHANGE_URL}|" $CONFIG_FILEfi
if [ ! -z "$EXCHANGE_MODE" ]; then sed -i "s|davmail.mode=.*|davmail.mode=${EXCHANGE_MODE}|" $CONFIG_FILEfi
if [ ! -z "$IMAP_PORT" ]; then sed -i "s|davmail.imapPort=.*|davmail.imapPort=${IMAP_PORT}|" $CONFIG_FILEfi
if [ ! -z "$SMTP_PORT" ]; then sed -i "s|davmail.smtpPort=.*|davmail.smtpPort=${SMTP_PORT}|" $CONFIG_FILEfi
if [ ! -z "$CALDAV_PORT" ]; then sed -i "s|davmail.caldavPort=.*|davmail.caldavPort=${CALDAV_PORT}|" $CONFIG_FILEfi
if [ ! -z "$LOG_LEVEL" ]; then sed -i "s|davmail.rootLoggingLevel=.*|davmail.rootLoggingLevel=${LOG_LEVEL}|" $CONFIG_FILEfi
# Start DavMailexec /opt/davmail/davmail $CONFIG_FILEStep 5: Create .dockerignore
Create a .dockerignore file to optimize the build:
.git.gitignore.env.env.local*.mdREADME.md.DS_StoreThumbs.dblogs/*.logStep 6: Create Environment Configuration
Create a .env.example file with configuration options:
# Exchange Server ConfigurationEXCHANGE_URL=https://outlook.office365.com/EWS/Exchange.asmxEXCHANGE_MODE=EWS
# Protocol Ports (internal to container)IMAP_PORT=1143POP_PORT=1110SMTP_PORT=1025CALDAV_PORT=1080LDAP_PORT=1389
# Logging ConfigurationLOG_LEVEL=INFO
# OAuth2 Configuration (for Office 365)# Use default DavMail client ID or register your ownOAUTH_CLIENT_ID=d3590ed6-52b3-4102-aeff-aad2292ab01cOAUTH_REDIRECT_URI=http://localhost:8080/
# Optional: Pre-configured credentials (not recommended for security)# DAVMAIL_USERNAME=user@domain.com# DAVMAIL_PASSWORD=passwordStep 7: Create Documentation
Create README.md:
# DavMail Gateway Deployment
This repository contains a DavMail deployment configured for Klutch.sh.
## Features
- Full protocol support (IMAP, POP, SMTP, CalDAV, CardDAV, LDAP)- Office 365 and Exchange Server compatibility- OAuth2 authentication support- Headless server mode- Multi-user support
## Configuration
Edit `davmail.properties` to configure your Exchange server URL and protocol settings.
For Office 365:davmail.url=https://outlook.office365.com/EWS/Exchange.asmx
For on-premises Exchange:davmail.url=https://your-exchange-server.com/owa/
## Email Client Setup
After deployment, configure your email client with these settings:
**IMAP:**- Server: example-app.klutch.sh- Port: 8000 (or your configured TCP port)- Security: STARTTLS- Username: your-email@domain.com- Password: your-exchange-password
**SMTP:**- Server: example-app.klutch.sh- Port: 8000 (or dedicated SMTP port)- Security: STARTTLS- Authentication: Required
## Deployment
This application is configured to deploy on Klutch.sh with automatic Docker detection.Step 8: Initialize Git Repository
git add .git commit -m "Initial DavMail setup for Klutch.sh deployment"git branch -M mastergit remote add origin https://github.com/yourusername/davmail-deployment.gitgit push -u origin masterDeploying to Klutch.sh
Now that your DavMail application is configured, let’s deploy it to Klutch.sh.
-
Log in to Klutch.sh
Navigate to klutch.sh/app and sign in with your GitHub account.
-
Create a New Project
Click “New Project” and select “Import from GitHub”. Choose the repository containing your DavMail deployment.
-
Configure Build Settings
Klutch.sh will automatically detect the Dockerfile in your repository. The platform will use this for building your container.
-
Configure Traffic Settings
Select “TCP” as the traffic type since DavMail serves multiple protocol ports. Traffic will be routed to port 8000, which you’ll need to configure as your primary protocol port (typically IMAP on port 1143 internally).
For multiple protocol access, you may need to configure port mapping or use a primary port for IMAP and access other protocols through additional service configurations.
-
Set Environment Variables
In the project settings, add the following environment variables:
EXCHANGE_URL: Your Exchange server URL (e.g.,https://outlook.office365.com/EWS/Exchange.asmxfor Office 365)EXCHANGE_MODE:EWS(for modern Exchange/Office 365) orWebDav(for older Exchange)IMAP_PORT:1143SMTP_PORT:1025CALDAV_PORT:1080LOG_LEVEL:INFO
For OAuth2 with Office 365:
OAUTH_CLIENT_ID:d3590ed6-52b3-4102-aeff-aad2292ab01c(DavMail default)OAUTH_REDIRECT_URI:http://localhost:8080/
-
Configure Persistent Storage
DavMail requires persistent storage for configuration and logs:
- Configuration and Logs Volume:
- Mount path:
/var/log/davmail - Size:
1GB
- Mount path:
This volume ensures your logs and cached OAuth tokens persist across deployments.
- Configuration and Logs Volume:
-
Deploy the Application
Click “Deploy” to start the build process. Klutch.sh will:
- Clone your repository
- Build the Docker image using your Dockerfile
- Download and install DavMail
- Deploy the container with protocol listeners
- Route TCP traffic to your gateway
The build process typically takes 2-3 minutes.
-
Access Your DavMail Gateway
Once deployment completes, Klutch.sh will provide a hostname. Your DavMail gateway will be accessible at
example-app.klutch.sh:8000for TCP connections.
Configuring Email Clients
Once your DavMail gateway is deployed, configure your email clients to connect through it:
Thunderbird Configuration
IMAP Setup:
-
Open Thunderbird and go to Account Settings
-
Click “Account Actions” → “Add Mail Account”
-
Enter your name, Office 365 email, and password
-
Click “Manual config”
-
Set these values:
- Incoming Server: IMAP
- Hostname: example-app.klutch.sh
- Port: 8000
- Security: STARTTLS
- Authentication: Normal password
- Username: your-email@company.com
-
Outgoing Server (SMTP):
- Hostname: example-app.klutch.sh
- Port: 8000 (or separate SMTP port if configured)
- Security: STARTTLS
- Authentication: Normal password
- Username: your-email@company.com
-
Click “Re-test” and then “Done”
Calendar Setup (CalDAV):
- Install “TbSync” and “Provider for CalDAV & CardDAV” add-ons
- Go to Tools → TbSync → Account Actions → Add new Account
- Select “CalDAV & CardDAV”
- Enter CalDAV URL:
http://example-app.klutch.sh:8000/users/your-email@company.com/calendar/ - Enter your Office 365 credentials
- Sync calendars
Apple Mail Configuration
Email Setup:
-
Open Mail → Preferences → Accounts
-
Click ”+” to add account
-
Select “Other Mail Account”
-
Enter name, email, and password
-
Click “Sign In”
-
If auto-detection fails, enter manual settings:
- Incoming Mail Server: example-app.klutch.sh
- Port: 8000
- Use SSL: Yes
- User Name: your-email@company.com
- Password: your-exchange-password
-
Outgoing Mail Server (SMTP):
- Server Name: example-app.klutch.sh
- Port: 8000
- Use SSL: Yes
- Authentication: Password
Calendar Setup:
- Open Calendar → Preferences → Accounts
- Click ”+” to add account
- Select “Other CalDAV Account”
- Account Type: Advanced
- User Name: your-email@company.com
- Password: your-exchange-password
- Server Address: example-app.klutch.sh
- Server Path: /users/your-email@company.com/calendar/
- Port: 8000
- Use SSL: Yes
Mobile Device Configuration (iOS/Android)
iOS Mail Setup:
- Settings → Mail → Accounts → Add Account
- Select “Other”
- Tap “Add Mail Account”
- Enter name, email, password, and description
- Tap “Next”
- Select “IMAP”
- Incoming Mail Server:
- Host Name: example-app.klutch.sh
- User Name: your-email@company.com
- Password: your-exchange-password
- Outgoing Mail Server: (same settings)
- Tap “Next” and “Save”
Android (K-9 Mail or similar):
- Open email app → Settings → Add Account
- Enter email address
- Select “IMAP”
- Incoming Server:
- IMAP Server: example-app.klutch.sh
- Security: STARTTLS
- Port: 8000
- Username: your-email@company.com
- Password: your-exchange-password
- Outgoing Server: (similar settings with SMTP)
- Complete setup
Evolution (Linux)
Mail Setup:
- Edit → Preferences → Mail Accounts → Add
- Enter identity information
- Server Type: IMAP
- Server: example-app.klutch.sh
- Port: 8000
- Username: your-email@company.com
- Encryption: STARTTLS
- Authentication: Password
- Configure SMTP with similar settings
Calendar:
- New → Calendar
- Type: CalDAV
- URL: http://example-app.klutch.sh:8000/users/your-email@company.com/calendar/
- Enter credentials
Advanced Configuration
Office 365 OAuth2 Setup
For enhanced security with Office 365, configure OAuth2 authentication:
Step 1: Register Application in Azure AD (Optional)
If using custom OAuth credentials:
- Go to Azure Portal
- Navigate to Azure Active Directory → App Registrations
- Click “New registration”
- Name: “DavMail Gateway”
- Supported account types: “Accounts in this organizational directory only”
- Redirect URI:
http://localhost:8080/(for OAuth flow) - Click “Register”
- Note the “Application (client) ID”
- Go to “Certificates & secrets” → “New client secret”
- Create and note the secret value
- Go to “API permissions” → “Add permission”
- Select “Microsoft Graph” → “Delegated permissions”
- Add: Mail.ReadWrite, Mail.Send, Calendars.ReadWrite, Contacts.ReadWrite
- Click “Grant admin consent”
Step 2: Update DavMail Configuration
Update your davmail.properties:
davmail.oauth.clientId=your-application-iddavmail.oauth.clientSecret=your-client-secretdavmail.oauth.redirectUri=http://localhost:8080/davmail.oauth.tenantId=your-tenant-idOr set via environment variables in Klutch.sh.
Step 3: First-Time Authentication
On first connection, DavMail will open a browser window (or provide a URL) for OAuth consent. Follow the prompts to authorize access. DavMail will cache the token for subsequent connections.
Custom SSL Certificates
To use custom SSL certificates for client connections:
Step 1: Prepare Certificate Files
Create a certs/ directory with your certificate files:
certs/ ├── server.crt ├── server.key └── ca.crtStep 2: Update Dockerfile
# Copy SSL certificatesRUN mkdir -p /etc/davmail/certsCOPY --chown=davmail:davmail certs/ /etc/davmail/certs/
# Import certificates into Java keystoreRUN keytool -import -trustcacerts -alias davmail \ -file /etc/davmail/certs/ca.crt \ -keystore /opt/java/openjdk/lib/security/cacerts \ -storepass changeit -nopromptStep 3: Update Configuration
Add to davmail.properties:
davmail.ssl.keystoreType=PKCS12davmail.ssl.keystoreFile=/etc/davmail/certs/server.p12davmail.ssl.keystorePass=your-keystore-passworddavmail.ssl.keyPass=your-key-passwordMulti-User Deployment with Different Exchange Servers
For organizations with users on different Exchange servers, you can deploy multiple DavMail instances or configure client-specific routing:
Option 1: Multiple Deployments
Deploy separate DavMail instances for each Exchange server, each with its own configuration.
Option 2: Client-Side Configuration
Use empty davmail.username and davmail.password in the properties file, allowing each client to provide its own credentials. DavMail will establish separate Exchange connections per authenticated client.
Logging and Debugging
Enable detailed logging for troubleshooting:
davmail.rootLoggingLevel=DEBUGdavmail.log4j.logger.davmail=DEBUGdavmail.log4j.logger.httpclient.wire=DEBUGdavmail.log4j.logger.org.apache.commons.httpclient=DEBUGAccess logs through the persistent volume or container logs:
# View logs through Klutch.sh dashboard or CLI toolsdocker logs davmail-containerLog files are stored in /var/log/davmail/ and rotated based on size configuration.
Performance Tuning
Connection Pooling:
davmail.keepAlive=truedavmail.enableKeepalive=truedavmail.keepDelay=300davmail.sentKeepDelay=3600Memory Settings:
Update Dockerfile to increase JVM heap:
ENV JAVA_OPTS="-Xmx512m -Xms256m"CMD ["sh", "-c", "./davmail ${JAVA_OPTS} /etc/davmail/davmail.properties"]Concurrent Connections:
DavMail handles multiple concurrent client connections by default. For high-traffic scenarios, increase container resources in Klutch.sh.
Calendar and Contact Synchronization
Calendar Settings:
# Sync past 90 days of calendar eventsdavmail.caldavPastDelay=90
# Enable automatic event schedulingdavmail.caldavAutoSchedule=true
# Calendar folder name mappingdavmail.caldavFolderName=CalendarContact Settings:
# Enable CardDAV for contactsdavmail.enableCarddav=true
# Contact folder mappingdavmail.carddavFolderName=ContactsLDAP Directory Access
Enable LDAP for Global Address List (GAL) lookups:
davmail.enableLdap=truedavmail.ldapPort=1389
# Allow anonymous LDAP bindsdavmail.ldapAnonymous=trueConfigure email clients to use LDAP for address book lookups:
- LDAP Server: example-app.klutch.sh
- Port: 8000 (mapped to internal 1389)
- Base DN: ou=people
- Search Filter: (cn=*)
Production Best Practices
Follow these recommendations for running DavMail in production:
Security
Credential Management
Never hardcode credentials in davmail.properties. Use empty username/password fields and let clients authenticate:
davmail.username=davmail.password=This allows each user to provide their own credentials securely.
OAuth2 for Office 365
Always prefer OAuth2 over password authentication for Office 365:
davmail.oauth.clientId=d3590ed6-52b3-4102-aeff-aad2292ab01cdavmail.oauth.redirectUri=http://localhost:8080/OAuth2 provides better security and doesn’t require storing passwords.
SSL/TLS Encryption
Ensure all protocol connections use encryption:
davmail.ssl.nosecurepop=falsedavmail.ssl.nosecureimap=falsedavmail.ssl.nosecuresmtp=falsedavmail.ssl.nosecurecaldav=falsedavmail.ssl.nosecureldap=falseNetwork Isolation
If possible, restrict DavMail access to specific IP ranges or VPN connections. Use firewall rules or network policies in your deployment environment.
Monitoring
Health Checks
Monitor DavMail availability by checking protocol ports:
# Check IMAP portnc -zv example-app.klutch.sh 8000
# Check through telnettelnet example-app.klutch.sh 8000Log Monitoring
Regularly review logs for authentication failures, connection errors, or performance issues:
tail -f /var/log/davmail/davmail.logLook for patterns like:
- Repeated authentication failures (possible brute force)
- Connection timeouts (Exchange server issues)
- SSL/TLS errors (certificate problems)
Performance Metrics
Monitor these metrics:
- Connection count (concurrent client connections)
- Response times (Exchange API latency)
- Memory usage (JVM heap utilization)
- Log file growth (disk space usage)
Backup and Recovery
Configuration Backup
Regularly backup your davmail.properties file:
cp /etc/davmail/davmail.properties /backup/davmail.properties.$(date +%Y%m%d)OAuth Token Backup
If using OAuth2, backup cached tokens (stored in log directory):
tar -czf davmail-tokens-backup.tar.gz /var/log/davmail/Disaster Recovery
Document your Exchange server URLs and OAuth configuration for quick recovery. Keep this information in a secure location separate from your deployment.
Scaling Considerations
Horizontal Scaling
For high-availability, deploy multiple DavMail instances behind a load balancer. Each instance can handle connections independently.
Resource Allocation
Typical resource requirements:
- CPU: 0.5-1 core for up to 50 concurrent users
- Memory: 512MB-1GB JVM heap
- Storage: 1GB for logs and configuration
- Network: Bandwidth depends on email volume
Connection Limits
Each DavMail instance can handle hundreds of concurrent connections. Monitor and scale based on:
- Number of active email clients
- Email sync frequency
- Calendar event complexity
- Attachment sizes
Update Strategy
Version Updates
To update DavMail:
- Check release notes at DavMail downloads
- Update
DAVMAIL_VERSIONin Dockerfile - Test in development environment
- Deploy to production
- Verify all protocols function correctly
Rolling Updates
If running multiple instances, update one at a time to maintain availability during upgrades.
Troubleshooting
Connection Issues
Problem: Cannot connect to DavMail from email client
Solutions:
- Verify deployment is running in Klutch.sh dashboard
- Check that TCP routing is configured on port 8000
- Test connectivity:
telnet example-app.klutch.sh 8000 - Verify firewall rules allow outbound connections
- Check client configuration matches server settings
- Review DavMail logs for connection attempts
Problem: “Connection refused” errors
Solutions:
- Confirm protocol ports are exposed in Dockerfile
- Verify
davmail.bindAddress=0.0.0.0in configuration - Check container is listening on expected ports:
netstat -tlnp - Ensure no port conflicts within container
- Restart deployment if ports aren’t binding
Authentication Issues
Problem: “Authentication failed” with Office 365
Solutions:
- Verify Exchange URL is correct:
https://outlook.office365.com/EWS/Exchange.asmx - Check username format (should be full email address)
- For OAuth2, ensure redirect URI matches configuration
- Verify OAuth client ID is valid
- Check if multi-factor authentication (MFA) is required
- Try basic authentication first to isolate OAuth issues
- Review Exchange/Office 365 audit logs for blocked login attempts
Problem: OAuth2 token not refreshing
Solutions:
- Delete cached token files in
/var/log/davmail/ - Verify OAuth client secret hasn’t expired
- Check token expiration settings in Azure AD
- Ensure proper API permissions are granted
- Re-authenticate manually to refresh token
Exchange Server Issues
Problem: “Unable to find Exchange server” error
Solutions:
- Verify Exchange URL is accessible from container
- Test URL manually:
curl -I https://outlook.office365.com/EWS/Exchange.asmx - Check for corporate proxy requirements
- Verify DNS resolution works in container
- For on-premises Exchange, ensure VPN/network access
- Try auto-discovery URL if specific URL fails
Problem: Slow synchronization or timeouts
Solutions:
-
Increase timeout values in
davmail.properties:davmail.keepDelay=600davmail.sentKeepDelay=7200 -
Check Exchange server health and performance
-
Reduce sync frequency in email clients
-
Monitor network latency to Exchange server
-
Consider using EWS mode instead of WebDav for better performance
Protocol-Specific Issues
Problem: IMAP folders not synchronizing
Solutions:
- Enable IMAP auto-expunge:
davmail.imapAutoExpunge=true - Check folder name mappings in configuration
- Verify Exchange folder permissions
- Review IMAP logs for specific folder errors
- Try manual folder subscription in email client
Problem: SMTP sending fails
Solutions:
- Verify SMTP port is correctly configured
- Check
davmail.smtpSaveInSent=truefor sent folder saving - Ensure SMTP authentication is enabled in client
- Verify Exchange allows SMTP relay for your account
- Check for attachment size limits
- Review SMTP logs for specific error codes
Problem: CalDAV calendar events not appearing
Solutions:
- Verify CalDAV URL format:
/users/email@domain.com/calendar/ - Check
davmail.caldavPastDelaysetting for historical event sync - Ensure calendar permissions in Exchange
- Try re-subscribing to calendar in client
- Check for timezone conversion issues
- Review CalDAV logs for sync errors
Performance Issues
Problem: High memory usage
Solutions:
- Increase JVM heap size in Dockerfile
- Monitor Java garbage collection
- Reduce concurrent connection count
- Check for memory leaks in logs
- Restart container periodically if memory doesn’t stabilize
- Review log file sizes (large logs consume memory)
Problem: Slow email client responses
Solutions:
- Enable connection keep-alive
- Optimize Exchange queries
- Reduce email fetch size in client
- Increase JVM memory allocation
- Check network latency to Exchange
- Monitor CPU usage and scale if needed
Logging Issues
Problem: Logs not persisting
Solutions:
- Verify persistent volume is mounted at
/var/log/davmail - Check directory permissions (should be writable by davmail user)
- Ensure adequate storage space in volume
- Review log rotation settings
- Test write access:
touch /var/log/davmail/test.log
Problem: Too many log files consuming storage
Solutions:
-
Reduce log retention:
davmail.logFileSize=1MBdavmail.logFileCount=5 -
Implement log rotation
-
Lower log level from DEBUG to INFO
-
Archive old logs to external storage
-
Increase volume size in Klutch.sh
Additional Resources
- DavMail Official Website
- Getting Started Guide
- Server Setup Documentation
- Frequently Asked Questions
- SourceForge Project Page
- SSL Configuration Guide
- Klutch.sh Documentation
- Persistent Volumes Guide
Conclusion
DavMail bridges the gap between Microsoft Exchange’s proprietary protocols and the standard email protocols that work with virtually any email client. By deploying DavMail as a gateway, you gain the freedom to use your preferred email client, calendar application, and contact manager while still accessing your Exchange or Office 365 account.
Deploying on Klutch.sh gives you the benefits of a cloud-hosted gateway without managing infrastructure. Your email clients can connect from anywhere, and the gateway handles the complexity of Exchange authentication, protocol translation, and connection management. Whether you’re supporting a team that prefers Thunderbird, enabling mobile email access with standard protocols, or simply want to use Apple Mail with your corporate Exchange account, DavMail on Klutch.sh provides the solution.
Start using your favorite email client with Exchange today and enjoy the freedom of standard protocols.