On Debian/Ubuntu systems, Exim4 uses a split configuration system that can be confusing at first glance. The main components are:
/etc/exim4/
├── exim4.conf.template
├── update-exim4.conf.conf
└── conf.d/
├── acl/
├── main/
├── router/
└── transport/
The uppercase variables (like MAILDIR_HOME_MAILDIR_LOCATION) are macros that can be defined in several places:
- update-exim4.conf.conf: This is the primary configuration file that gets processed first.
- Environment variables: When running update-exim4.conf
- Debconf database: Through dpkg-reconfigure exim4-config
To change these configuration macros, you have several options:
# Method 1: Edit update-exim4.conf.conf directly
sudo nano /etc/exim4/update-exim4.conf.conf
# Add or modify lines like:
MAILDIR_HOME_MAILDIR_LOCATION='/custom/maildir/path'
# Method 2: Use dpkg-reconfigure
sudo dpkg-reconfigure exim4-config
# Method 3: Set them during update
sudo MAILDIR_HOME_MAILDIR_LOCATION='/alternate/path' update-exim4.conf
The numerous if statements serve several important purposes:
- Flexibility: Allows different configurations for different setups (local delivery vs. remote)
- Debian packaging: Makes it easier to maintain different configuration scenarios
- Customization: Lets administrators override defaults without modifying template files
Let's implement a custom Maildir location across the configuration:
# First, edit the configuration file
echo "MAILDIR_HOME_MAILDIR_LOCATION='/mnt/storage/maildirs'" | sudo tee -a /etc/exim4/update-exim4.conf.conf
# Then update the configuration
sudo update-exim4.conf
# Verify the change
sudo grep -r "MAILDIR_HOME_MAILDIR_LOCATION" /etc/exim4
When troubleshooting, these commands are invaluable:
# Check the effective configuration
exim4 -bV
# Test a specific router or transport
exim4 -brt user@example.com
# Verify the configuration syntax
exim4 -C /etc/exim4/exim4.conf.template -bV
- Always run update-exim4.conf after making changes
- Keep customizations in update-exim4.conf.conf rather than modifying template files
- Use version control for your configuration changes
- Test configuration changes with exim4 -bh before applying them
The Exim4 mail server on Debian-based systems uses a unique split configuration structure:
/etc/exim4/
├── exim4.conf.template # Master template file
├── update-exim4.conf.conf # Configuration generator settings
└── conf.d/ # Modular configuration fragments
├── main/ # Core configuration
├── acl/ # Access control lists
├── router/ # Routing configuration
└── transport/ # Delivery methods
The uppercase variables (like MAILDIR_HOME_MAILDIR_LOCATION) can be defined in multiple places:
# Primary sources:
1. /etc/default/exim4
2. /etc/exim4/update-exim4.conf.conf
3. Directly in /etc/exim4/exim4.conf.template
4. Runtime through debconf system
For persistent changes, edit the update-exim4.conf.conf file:
# Example: Change maildir location
dc_eximconfig_configtype='internet'
dc_other_hostnames='example.com'
dc_local_interfaces='127.0.0.1'
dc_readhost=''
dc_relay_domains=''
dc_minimaldns='false'
dc_relay_nets=''
dc_smarthost=''
MAILDIR_HOME_MAILDIR_LOCATION='/var/mail/%u/Maildir'
After modifying, regenerate the configuration:
sudo update-exim4.conf
sudo service exim4 reload
The extensive use of .ifdef/.endif statements serves several purposes:
- Allows flexible configuration for different deployment scenarios
- Enables easy customization without modifying core files
- Supports the Debian package maintainer's configuration system
- Provides a clean way to handle distribution-specific defaults
Let's modify the maildir delivery location and create a custom transport:
# In /etc/exim4/conf.d/transport/40_exim4-config_maildir_home
maildir_home:
driver = appendfile
.ifdef CUSTOM_MAILDIR_PATH
directory = CUSTOM_MAILDIR_PATH/$local_part
.else
directory = /var/mail/$local_part/Maildir
.endif
maildir_format
delivery_date_add
envelope_to_add
return_path_add
group = mail
mode = 0660
Then define the variable in update-exim4.conf.conf:
CUSTOM_MAILDIR_PATH='/mnt/storage/mail'
To verify your configuration:
# Test configuration syntax
sudo exim4 -bV
# View expanded configuration
sudo exim4 -bP | less
# Test specific router or transport
sudo exim4 -brt user@example.com