Skip to content

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

  1. Email client connects to DavMail on protocol-specific port (IMAP, SMTP, etc.)
  2. DavMail authenticates the client connection
  3. Client sends protocol command (e.g., IMAP SELECT command to open a folder)
  4. DavMail translates command to Exchange API call
  5. Exchange server processes request and returns data
  6. DavMail formats Exchange response according to protocol specifications
  7. Response is sent back to email client
  8. Session state is maintained for subsequent requests
  9. 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:

Terminal window
mkdir davmail-deployment
cd davmail-deployment
git init

Step 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 URL
davmail.url=https://outlook.office365.com/EWS/Exchange.asmx
# Exchange mode: EWS, WebDav, or auto
davmail.mode=EWS
# Protocol Ports
davmail.imapPort=1143
davmail.popPort=1110
davmail.smtpPort=1025
davmail.caldavPort=1080
davmail.ldapPort=1389
# Bind all protocols to all interfaces (required for Docker)
davmail.bindAddress=0.0.0.0
# Enable all protocols
davmail.enableImap=true
davmail.enablePop=true
davmail.enableSmtp=true
davmail.enableCaldav=true
davmail.enableLdap=true
# Authentication settings
# Leave empty for client-provided credentials
davmail.username=
davmail.password=
# OAuth settings for Office 365
davmail.oauth.clientId=d3590ed6-52b3-4102-aeff-aad2292ab01c
davmail.oauth.redirectUri=http://localhost:8080/
# SSL/TLS Settings
davmail.ssl.nosecurepop=false
davmail.ssl.nosecureimap=false
davmail.ssl.nosecuresmtp=false
davmail.ssl.nosecurecaldav=false
davmail.ssl.nosecureldap=false
# Disable GUI mode for headless operation
davmail.server=true
davmail.disableGuiNotifications=true
davmail.showStartupBanner=false
# Logging
davmail.logFilePath=/var/log/davmail/
davmail.logFileSize=1MB
davmail.rootLoggingLevel=INFO
# Timeouts (in seconds)
davmail.keepDelay=300
davmail.sentKeepDelay=3600
# Calendar and contact settings
davmail.caldavPastDelay=90
davmail.caldavAutoSchedule=true
davmail.forceActiveSyncUpdate=false
# IMAP folder mappings
davmail.defaultDomain=
davmail.imapAutoExpunge=true
davmail.smtpSaveInSent=true
# Connection pooling
davmail.keepAlive=true
davmail.enableKeepalive=true

For 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 variables
ENV DAVMAIL_VERSION=6.2.1 \
DAVMAIL_HOME=/opt/davmail \
DAVMAIL_CONF=/etc/davmail \
DAVMAIL_LOG=/var/log/davmail
# Install dependencies
RUN apk add --no-cache \
bash \
curl \
ca-certificates \
tzdata
# Create directories
RUN mkdir -p ${DAVMAIL_HOME} ${DAVMAIL_CONF} ${DAVMAIL_LOG}
# Download and install DavMail
RUN 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 user
RUN addgroup -g 1000 davmail && \
adduser -D -u 1000 -G davmail davmail && \
chown -R davmail:davmail ${DAVMAIL_HOME} ${DAVMAIL_CONF} ${DAVMAIL_LOG}
# Copy configuration
COPY --chown=davmail:davmail davmail.properties ${DAVMAIL_CONF}/
# Switch to davmail user
USER davmail
# Expose protocol ports
EXPOSE 1143 1110 1025 1080 1389
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD nc -z localhost 1143 || exit 1
# Set working directory
WORKDIR ${DAVMAIL_HOME}
# Start DavMail
CMD ["./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 provided
if [ ! -z "$EXCHANGE_URL" ]; then
sed -i "s|davmail.url=.*|davmail.url=${EXCHANGE_URL}|" $CONFIG_FILE
fi
if [ ! -z "$EXCHANGE_MODE" ]; then
sed -i "s|davmail.mode=.*|davmail.mode=${EXCHANGE_MODE}|" $CONFIG_FILE
fi
if [ ! -z "$IMAP_PORT" ]; then
sed -i "s|davmail.imapPort=.*|davmail.imapPort=${IMAP_PORT}|" $CONFIG_FILE
fi
if [ ! -z "$SMTP_PORT" ]; then
sed -i "s|davmail.smtpPort=.*|davmail.smtpPort=${SMTP_PORT}|" $CONFIG_FILE
fi
if [ ! -z "$CALDAV_PORT" ]; then
sed -i "s|davmail.caldavPort=.*|davmail.caldavPort=${CALDAV_PORT}|" $CONFIG_FILE
fi
if [ ! -z "$LOG_LEVEL" ]; then
sed -i "s|davmail.rootLoggingLevel=.*|davmail.rootLoggingLevel=${LOG_LEVEL}|" $CONFIG_FILE
fi
# Start DavMail
exec /opt/davmail/davmail $CONFIG_FILE

Step 5: Create .dockerignore

Create a .dockerignore file to optimize the build:

.git
.gitignore
.env
.env.local
*.md
README.md
.DS_Store
Thumbs.db
logs/
*.log

Step 6: Create Environment Configuration

Create a .env.example file with configuration options:

Terminal window
# Exchange Server Configuration
EXCHANGE_URL=https://outlook.office365.com/EWS/Exchange.asmx
EXCHANGE_MODE=EWS
# Protocol Ports (internal to container)
IMAP_PORT=1143
POP_PORT=1110
SMTP_PORT=1025
CALDAV_PORT=1080
LDAP_PORT=1389
# Logging Configuration
LOG_LEVEL=INFO
# OAuth2 Configuration (for Office 365)
# Use default DavMail client ID or register your own
OAUTH_CLIENT_ID=d3590ed6-52b3-4102-aeff-aad2292ab01c
OAUTH_REDIRECT_URI=http://localhost:8080/
# Optional: Pre-configured credentials (not recommended for security)
# DAVMAIL_USERNAME=user@domain.com
# DAVMAIL_PASSWORD=password

Step 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

Terminal window
git add .
git commit -m "Initial DavMail setup for Klutch.sh deployment"
git branch -M master
git remote add origin https://github.com/yourusername/davmail-deployment.git
git push -u origin master

Deploying to Klutch.sh

Now that your DavMail application is configured, let’s deploy it to Klutch.sh.

  1. Log in to Klutch.sh

    Navigate to klutch.sh/app and sign in with your GitHub account.

  2. Create a New Project

    Click “New Project” and select “Import from GitHub”. Choose the repository containing your DavMail deployment.

  3. Configure Build Settings

    Klutch.sh will automatically detect the Dockerfile in your repository. The platform will use this for building your container.

  4. 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.

  5. 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.asmx for Office 365)
    • EXCHANGE_MODE: EWS (for modern Exchange/Office 365) or WebDav (for older Exchange)
    • IMAP_PORT: 1143
    • SMTP_PORT: 1025
    • CALDAV_PORT: 1080
    • LOG_LEVEL: INFO

    For OAuth2 with Office 365:

    • OAUTH_CLIENT_ID: d3590ed6-52b3-4102-aeff-aad2292ab01c (DavMail default)
    • OAUTH_REDIRECT_URI: http://localhost:8080/
  6. Configure Persistent Storage

    DavMail requires persistent storage for configuration and logs:

    • Configuration and Logs Volume:
      • Mount path: /var/log/davmail
      • Size: 1GB

    This volume ensures your logs and cached OAuth tokens persist across deployments.

  7. 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.

  8. Access Your DavMail Gateway

    Once deployment completes, Klutch.sh will provide a hostname. Your DavMail gateway will be accessible at example-app.klutch.sh:8000 for TCP connections.

Configuring Email Clients

Once your DavMail gateway is deployed, configure your email clients to connect through it:

Thunderbird Configuration

IMAP Setup:

  1. Open Thunderbird and go to Account Settings

  2. Click “Account Actions” → “Add Mail Account”

  3. Enter your name, Office 365 email, and password

  4. Click “Manual config”

  5. Set these values:

    • Incoming Server: IMAP
    • Hostname: example-app.klutch.sh
    • Port: 8000
    • Security: STARTTLS
    • Authentication: Normal password
    • Username: your-email@company.com
  6. 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
  7. Click “Re-test” and then “Done”

Calendar Setup (CalDAV):

  1. Install “TbSync” and “Provider for CalDAV & CardDAV” add-ons
  2. Go to Tools → TbSync → Account Actions → Add new Account
  3. Select “CalDAV & CardDAV”
  4. Enter CalDAV URL: http://example-app.klutch.sh:8000/users/your-email@company.com/calendar/
  5. Enter your Office 365 credentials
  6. Sync calendars

Apple Mail Configuration

Email Setup:

  1. Open Mail → Preferences → Accounts

  2. Click ”+” to add account

  3. Select “Other Mail Account”

  4. Enter name, email, and password

  5. Click “Sign In”

  6. 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
  7. Outgoing Mail Server (SMTP):

    • Server Name: example-app.klutch.sh
    • Port: 8000
    • Use SSL: Yes
    • Authentication: Password

Calendar Setup:

  1. Open Calendar → Preferences → Accounts
  2. Click ”+” to add account
  3. Select “Other CalDAV Account”
  4. Account Type: Advanced
  5. User Name: your-email@company.com
  6. Password: your-exchange-password
  7. Server Address: example-app.klutch.sh
  8. Server Path: /users/your-email@company.com/calendar/
  9. Port: 8000
  10. Use SSL: Yes

Mobile Device Configuration (iOS/Android)

iOS Mail Setup:

  1. Settings → Mail → Accounts → Add Account
  2. Select “Other”
  3. Tap “Add Mail Account”
  4. Enter name, email, password, and description
  5. Tap “Next”
  6. Select “IMAP”
  7. Incoming Mail Server:
  8. Outgoing Mail Server: (same settings)
  9. Tap “Next” and “Save”

Android (K-9 Mail or similar):

  1. Open email app → Settings → Add Account
  2. Enter email address
  3. Select “IMAP”
  4. Incoming Server:
    • IMAP Server: example-app.klutch.sh
    • Security: STARTTLS
    • Port: 8000
    • Username: your-email@company.com
    • Password: your-exchange-password
  5. Outgoing Server: (similar settings with SMTP)
  6. Complete setup

Evolution (Linux)

Mail Setup:

  1. Edit → Preferences → Mail Accounts → Add
  2. Enter identity information
  3. Server Type: IMAP
  4. Server: example-app.klutch.sh
  5. Port: 8000
  6. Username: your-email@company.com
  7. Encryption: STARTTLS
  8. Authentication: Password
  9. Configure SMTP with similar settings

Calendar:

  1. New → Calendar
  2. Type: CalDAV
  3. URL: http://example-app.klutch.sh:8000/users/your-email@company.com/calendar/
  4. 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:

  1. Go to Azure Portal
  2. Navigate to Azure Active Directory → App Registrations
  3. Click “New registration”
  4. Name: “DavMail Gateway”
  5. Supported account types: “Accounts in this organizational directory only”
  6. Redirect URI: http://localhost:8080/ (for OAuth flow)
  7. Click “Register”
  8. Note the “Application (client) ID”
  9. Go to “Certificates & secrets” → “New client secret”
  10. Create and note the secret value
  11. Go to “API permissions” → “Add permission”
  12. Select “Microsoft Graph” → “Delegated permissions”
  13. Add: Mail.ReadWrite, Mail.Send, Calendars.ReadWrite, Contacts.ReadWrite
  14. Click “Grant admin consent”

Step 2: Update DavMail Configuration

Update your davmail.properties:

davmail.oauth.clientId=your-application-id
davmail.oauth.clientSecret=your-client-secret
davmail.oauth.redirectUri=http://localhost:8080/
davmail.oauth.tenantId=your-tenant-id

Or 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.crt

Step 2: Update Dockerfile

# Copy SSL certificates
RUN mkdir -p /etc/davmail/certs
COPY --chown=davmail:davmail certs/ /etc/davmail/certs/
# Import certificates into Java keystore
RUN keytool -import -trustcacerts -alias davmail \
-file /etc/davmail/certs/ca.crt \
-keystore /opt/java/openjdk/lib/security/cacerts \
-storepass changeit -noprompt

Step 3: Update Configuration

Add to davmail.properties:

davmail.ssl.keystoreType=PKCS12
davmail.ssl.keystoreFile=/etc/davmail/certs/server.p12
davmail.ssl.keystorePass=your-keystore-password
davmail.ssl.keyPass=your-key-password

Multi-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=DEBUG
davmail.log4j.logger.davmail=DEBUG
davmail.log4j.logger.httpclient.wire=DEBUG
davmail.log4j.logger.org.apache.commons.httpclient=DEBUG

Access logs through the persistent volume or container logs:

Terminal window
# View logs through Klutch.sh dashboard or CLI tools
docker logs davmail-container

Log files are stored in /var/log/davmail/ and rotated based on size configuration.

Performance Tuning

Connection Pooling:

davmail.keepAlive=true
davmail.enableKeepalive=true
davmail.keepDelay=300
davmail.sentKeepDelay=3600

Memory 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 events
davmail.caldavPastDelay=90
# Enable automatic event scheduling
davmail.caldavAutoSchedule=true
# Calendar folder name mapping
davmail.caldavFolderName=Calendar

Contact Settings:

# Enable CardDAV for contacts
davmail.enableCarddav=true
# Contact folder mapping
davmail.carddavFolderName=Contacts

LDAP Directory Access

Enable LDAP for Global Address List (GAL) lookups:

davmail.enableLdap=true
davmail.ldapPort=1389
# Allow anonymous LDAP binds
davmail.ldapAnonymous=true

Configure 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-aad2292ab01c
davmail.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=false
davmail.ssl.nosecureimap=false
davmail.ssl.nosecuresmtp=false
davmail.ssl.nosecurecaldav=false
davmail.ssl.nosecureldap=false

Network 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:

Terminal window
# Check IMAP port
nc -zv example-app.klutch.sh 8000
# Check through telnet
telnet example-app.klutch.sh 8000

Log Monitoring

Regularly review logs for authentication failures, connection errors, or performance issues:

Terminal window
tail -f /var/log/davmail/davmail.log

Look 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:

Terminal window
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):

Terminal window
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:

  1. Check release notes at DavMail downloads
  2. Update DAVMAIL_VERSION in Dockerfile
  3. Test in development environment
  4. Deploy to production
  5. 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.0 in 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=600
    davmail.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=true for 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.caldavPastDelay setting 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=1MB
    davmail.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

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.