This article provides a guide to install and run Modoboa email server on Debian VPS.
Step-by-Step Guide to Install and Run Modoboa on a Debian VPS
Modoboa is a complete mail hosting and management platform that simplifies the deployment of email services. Here’s a step-by-step guide to install and run Modoboa on a Debian VPS.
Prerequisites
Before starting, ensure the following:
- A VPS running Debian (Debian 11 “Bullseye” or Debian 12 “Bookworm” is recommended).
- A fully qualified domain name (FQDN) configured for your VPS (e.g.,
mail.yourdomain.com
). - Root access or a user with sudo privileges.
- Port 25 open for outbound traffic (verify with your hosting provider if blocked).
Install and Run Modoboa Email Server on Debian VPS
To install and run Modoboa email server on Debian VPS, follow the steps below:
-
Update the System
- Log in to your Debian VPS:
ssh user@your-server-ip
- Update your package list and upgrade installed packages:
sudo apt update && sudo apt upgrade -y
- Log in to your Debian VPS:
-
Configure DNS Records
To host an email server, set up the necessary DNS records for your domain:
- A Record: Point
mail.yourdomain.com
to your VPS IP. - MX Record: Set your domain’s mail server to
mail.yourdomain.com
. - SPF Record: Add an SPF TXT record (example):
"v=spf1 mx -all"
- DKIM Record: This will be generated later by Modoboa.
- DMARC Record: Optional but recommended (example):
"v=DMARC1; p=none; rua=mailto:dmarc-reports@yourdomain.com"
- A Record: Point
-
Install Dependencies
- Install basic dependencies:
sudo apt install -y git curl wget gnupg2 lsb-release
- Install Python and pip:
sudo apt install -y python3 python3-pip python3-venv
- Install database server (PostgreSQL):
sudo apt install -y postgresql
- Install basic dependencies:
-
Install Modoboa Installer
The Modoboa installer simplifies setup.
- Install the installer:
pip3 install modoboa-installer
- Verify the installation:
modoboa-installer --version
- Install the installer:
-
Prepare the Installation Directory
- Create a directory for Modoboa:
mkdir -p ~/modoboa && cd ~/modoboa
- Download the Modoboa configuration:
modoboa-installer init mail.yourdomain.com
- Edit the configuration file (optional):
nano installer.cfg
- Create a directory for Modoboa:
-
Run the Installer
- Start the installation:
modoboa-installer deploy mail.yourdomain.com
- The script will:
- Install and configure Nginx as the web server.
- Install and configure Postfix and Dovecot for SMTP and IMAP.
- Set up Let’s Encrypt SSL certificates (ensure your domain points to the VPS).
- Monitor the output for errors and follow any provided instructions.
- Start the installation:
-
Configure Modoboa
- Access the Modoboa web interface:
- Open your browser and navigate to
https://mail.yourdomain.com
. - Login with the default admin credentials:
- Username:
admin
- Password:
password
(change immediately after logging in).
- Username:
- Open your browser and navigate to
- Configure your mail domains and user accounts.
- Access the Modoboa web interface:
-
Test Email Services
- Send a test email to an external address (e.g., Gmail) to verify outbound mail.
- Use an external email to reply back and verify inbound mail.
- Check your domain’s DNS records using online tools like MXToolbox to ensure no configuration issues.
-
Optimize and Secure
- Enable Fail2Ban to protect against brute force attacks:
sudo apt install -y fail2ban
- Configure Firewall (UFW):
sudo apt install -y ufw sudo ufw allow OpenSSH sudo ufw allow 25,80,443,587,993/tcp sudo ufw enable
- Monitor logs:
- Check mail logs:
sudo tail -f /var/log/mail.log
- Check Modoboa logs:
sudo journalctl -u modoboa
- Check mail logs:
- Enable Fail2Ban to protect against brute force attacks:
-
Regular Maintenance
- Update the system and Modoboa regularly:
sudo apt update && sudo apt upgrade -y pip3 install --upgrade modoboa-installer
- Backup your data:
- Backup the database and configuration files periodically.
- Update the system and Modoboa regularly:
Troubleshooting
- If emails are marked as spam, check your SPF, DKIM, and DMARC records.
- Verify Modoboa logs for configuration issues.
- Ensure ports required for email services (e.g., 25, 587, 993) are open.
By following these steps, you’ll have a fully operational Modoboa mail server on your Debian VPS.
Initial Configuration After Modoboa Installation
After successfully installing Modoboa and logging in to the web interface, follow these steps for initial configuration to ensure your mail server is fully operational and secure.
-
Change Default Admin Password
- Log in to the Modoboa Admin interface at
https://mail.yourdomain.com
with the default credentials:- Username:
admin
- Password:
password
- Username:
- Navigate to the “Account” section in the top-right dropdown menu.
- Change the password to something secure:
- Use a combination of uppercase, lowercase, numbers, and special characters.
- Log in to the Modoboa Admin interface at
-
Add a Mail Domain
- Go to the “Domains” section in the admin dashboard.
- Click on “Add domain” and provide the following details:
- Domain name: Enter your domain (e.g.,
yourdomain.com
). - Default mail server address: This will typically be
mail.yourdomain.com
. - Options:
- Enable Domain alias if needed (e.g.,
example.org
as an alias forexample.com
). - Enable DKIM signing (recommended).
- Enable Domain alias if needed (e.g.,
- Domain name: Enter your domain (e.g.,
- Save the domain.
-
Generate DKIM Keys
If you enabled DKIM signing:
- Go to “Domains” > “DNS” for the newly added domain.
- Copy the DKIM public key provided in the interface.
- Add a TXT record to your domain’s DNS with the following details:
- Name:
dkim._domainkey.yourdomain.com
- Value: Paste the DKIM public key.
- TTL: Set to 3600 seconds (or default).
- Name:
- Wait for DNS propagation (this may take a few hours).
-
Configure Mail Users
- Navigate to the “Users” section in the admin dashboard.
- Click “Create” to add a new user:
- Username: The email address (e.g.,
user@yourdomain.com
). - First name/Last name: User’s name.
- Role: Choose
SimpleUser
for regular email users. - Password: Set a secure password or allow the system to generate one.
- Username: The email address (e.g.,
- Save the user and repeat for additional accounts.
-
Test Sending and Receiving Emails
- Log in to the webmail interface as a test user:
- Navigate to
https://mail.yourdomain.com/webmail
.
- Navigate to
- Send a test email to an external address (e.g., Gmail or Yahoo).
- Check for the email’s arrival in the recipient’s inbox (not spam). If the email goes to spam:
- Verify SPF, DKIM, and DMARC records in your DNS settings.
- Use tools like MXToolbox or Mail Tester to check email reputation and DNS setup.
- Reply to the test email to ensure inbound email functionality.
- Log in to the webmail interface as a test user:
-
Set Up SPF and DMARC Records
- Add the following TXT records to your DNS configuration:
- SPF Record:
Name: @ Value: v=spf1 mx -all TTL: 3600
This specifies that only your mail server is authorized to send emails for your domain.
- DMARC Record (optional but recommended):
Name: _dmarc Value: v=DMARC1; p=none; rua=mailto:dmarc-reports@yourdomain.com TTL: 3600
- SPF Record:
- Wait for DNS changes to propagate.
- Add the following TXT records to your DNS configuration:
-
Set Up Mail Relay (Optional)
If your hosting provider blocks outbound port 25, use a mail relay service:
- Sign up for a relay service like Mailgun or SendGrid.
- Configure the relay in Postfix by editing the configuration file:
sudo nano /etc/postfix/main.cf
- Add the relay settings (replace with your service credentials):
relayhost = [smtp.mailgun.org]:587 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_tls_security_level = encrypt smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
- Create the
sasl_passwd
file:sudo nano /etc/postfix/sasl_passwd
Add your relay credentials:
[smtp.mailgun.org]:587 username:password
- Apply the configuration:
sudo postmap /etc/postfix/sasl_passwd sudo systemctl restart postfix
-
Enable SSL/TLS
Ensure all email connections are encrypted:
- Modoboa installs Let’s Encrypt certificates automatically.
- Verify SSL/TLS status:
- Check
/etc/nginx/sites-enabled/mail.yourdomain.com
for SSL configuration. - Use online tools like SSL Labs to test your SSL setup.
- Check
-
Configure Auto-Renewal for Let’s Encrypt
- Verify that the Certbot renewal cron job is set:
sudo systemctl list-timers | grep certbot
- Test manual renewal:
sudo certbot renew --dry-run
- Verify that the Certbot renewal cron job is set:
-
Monitor and Maintain the Server
- Regularly check email logs:
sudo tail -f /var/log/mail.log
- Backup critical data:
- Mail data:
/var/mail/
- Modoboa settings and database.
- Mail data:
- Update Modoboa and dependencies:
pip3 install --upgrade modoboa
- Regularly check email logs:
By completing these steps, you’ll have a fully configured and operational Modoboa email server.
Integrate the modoboa-webmail
Extension with a Modoboa Server
The modoboa-webmail
extension provides webmail functionality to Modoboa, enabling users to send, receive, and manage emails directly from the Modoboa interface. Here’s how you can integrate and configure the extension on your Modoboa server:
-
Verify Prerequisites
- Modoboa Installed: Ensure you have Modoboa installed and running properly.
- Python and Pip: Confirm that
pip
and Python3 are installed on your server:python3 --version pip3 --version
- Database Backups: Create a backup of your Modoboa database and critical data before proceeding.
-
Install the
modoboa-webmail
Extension- Activate the Python virtual environment used by Modoboa:
source /srv/modoboa/env/bin/activate
- Install the
modoboa-webmail
extension usingpip
:pip install modoboa-webmail
- Verify the installation:
pip show modoboa-webmail
- Activate the Python virtual environment used by Modoboa:
-
Step 3: Update Modoboa Configuration
- Add the
modoboa-webmail
extension to Modoboa’s configuration:- Locate the
settings.py
file for Modoboa, typically found in/srv/modoboa/instance/instance/settings.py
. - Open the file with a text editor:
nano /srv/modoboa/instance/instance/settings.py
- Add the extension to the
INSTALLED_APPS
list:python INSTALLED_APPS += ( "modoboa_webmail", )
- Locate the
- Save and exit the file.
- Add the
-
Apply Database Migrations
Run migrations to add the necessary database tables for the
modoboa-webmail
extension:python manage.py migrate
-
Collect Static Files
Gather static files required by the webmail extension:
python manage.py collectstatic --noinput
-
Restart Services
- Restart the Modoboa instance to apply changes:
systemctl restart uwsgi
- Restart the Nginx service to reload configuration (if applicable):
systemctl restart nginx
- Restart the Modoboa instance to apply changes:
-
Enable and Configure Webmail in Modoboa
- Log in to the Modoboa Admin interface at
https://mail.yourdomain.com
. - Navigate to “Extensions” in the admin dashboard.
- Locate
modoboa-webmail
in the list of extensions and activate it. - Configure the webmail settings:
- Default IMAP settings:
- Host:
mail.yourdomain.com
- Port:
993
- SSL: Enabled
- Host:
- Default SMTP settings:
- Host:
mail.yourdomain.com
- Port:
587
- TLS: Enabled
- Host:
- Default IMAP settings:
- Log in to the Modoboa Admin interface at
-
Test Webmail Functionality
- Log in to the Modoboa web interface with a user account (not admin).
- Access the “Webmail” tab in the navigation bar.
- Send a test email to verify outbound functionality.
- Receive a test email to confirm inbound functionality.
-
Troubleshooting
- Check Logs: If you encounter issues, review the logs for detailed error messages:
- Modoboa logs:
sudo journalctl -u uwsgi
- Email service logs:
sudo tail -f /var/log/mail.log
- Modoboa logs:
- Verify DNS Records:
- Confirm SPF, DKIM, and DMARC are correctly configured to avoid email delivery issues.
- Debug IMAP/SMTP Settings:
- Use tools like
openssl
ortelnet
to verify connectivity:openssl s_client -connect mail.yourdomain.com:993
- Use tools like
- Check Logs: If you encounter issues, review the logs for detailed error messages:
-
Optional: Customize Webmail Appearance
- Modify the webmail interface by editing theme settings or CSS files:
- Locate the webmail static files directory:
/srv/modoboa/instance/static/modoboa_webmail/
- Locate the webmail static files directory:
- Make the desired changes and re-run
collectstatic
to apply.
- Modify the webmail interface by editing theme settings or CSS files:
By completing these steps, the modoboa-webmail
extension will be fully integrated and functional on your Modoboa server, allowing users to manage their emails directly through the Modoboa web interface.
Steps to Add modoboa-radicale
to Your Modoboa Server
The modoboa-radicale
extension integrates a CalDAV and CardDAV server (Radicale) into your Modoboa instance, enabling calendar and contact synchronization. Below is a step-by-step guide to install and configure it.
-
Prerequisites
- Ensure Modoboa is Installed: You must have a functioning Modoboa instance.
- Python Virtual Environment: You should be using a virtual environment for Modoboa (typically located in
/srv/modoboa/env
). - Backup Your System: Create a backup of your Modoboa database and configuration before proceeding.
-
Install Radicale
- Install Radicale from the Debian repositories:
sudo apt install radicale
- Verify Radicale installation:
radicale --version
- Install Radicale from the Debian repositories:
-
Install the
modoboa-radicale
Extension- Activate the Python virtual environment for Modoboa:
source /srv/modoboa/env/bin/activate
- Install the
modoboa-radicale
extension:pip install modoboa-radicale
- Verify the installation:
pip show modoboa-radicale
- Activate the Python virtual environment for Modoboa:
-
Update Modoboa Configuration
- Add the
modoboa-radicale
extension to the Modoboa configuration file:- Open
settings.py
(located at/srv/modoboa/instance/instance/settings.py
):nano /srv/modoboa/instance/instance/settings.py
- Add
modoboa_radicale
to theINSTALLED_APPS
list:python INSTALLED_APPS += ( "modoboa_radicale", )
- Open
- Save and close the file.
- Add the
-
Apply Database Migrations
Run the migrations to add database tables for the
modoboa-radicale
extension:python manage.py migrate
-
Collect Static Files
Gather static files for the
modoboa-radicale
extension:python manage.py collectstatic --noinput
-
Configure Radicale
- Modify the Radicale configuration file (
/etc/radicale/config
):sudo nano /etc/radicale/config
- Update the configuration with the following settings:
[server] hosts = 0.0.0.0:5232 base_prefix = /radicale/ [auth] type = none [storage] filesystem_folder = /var/lib/radicale/collections
- Save the file and restart the Radicale service:
sudo systemctl restart radicale
- Modify the Radicale configuration file (
-
Enable and Configure the Extension in Modoboa
- Log in to the Modoboa Admin interface at
https://mail.yourdomain.com
. - Go to Extensions > modoboa-radicale and activate it.
- Configure default settings for calendars and contacts:
- URL:
http://127.0.0.1:5232/radicale/
- URL:
- Log in to the Modoboa Admin interface at
-
Test Radicale Integration
- Log in to the Modoboa web interface with a user account.
- Navigate to Settings > Calendar/Contacts to verify access to CalDAV and CardDAV services.
-
Optional: Enable SSL for Radicale
If you want to secure the Radicale server:
- Edit the Radicale configuration to enable SSL:
[server] ssl = True certificate = /etc/letsencrypt/live/mail.yourdomain.com/fullchain.pem key = /etc/letsencrypt/live/mail.yourdomain.com/privkey.pem
- Restart the Radicale service:
sudo systemctl restart radicale
- Update the Radicale URL in Modoboa to
https://mail.yourdomain.com/radicale/
.
- Edit the Radicale configuration to enable SSL:
-
Sync Calendars and Contacts
- Use a CalDAV/CardDAV client (e.g., Thunderbird, Outlook, iOS, or Android) to sync data:
- CalDAV URL:
https://mail.yourdomain.com/radicale/user@example.com/calendar/
- CardDAV URL:
https://mail.yourdomain.com/radicale/user@example.com/addressbook/
- Username: Your Modoboa email address.
- Password: Your Modoboa account password.
- CalDAV URL:
- Test synchronization for both calendars and contacts.
- Use a CalDAV/CardDAV client (e.g., Thunderbird, Outlook, iOS, or Android) to sync data:
-
Monitor and Maintain
- Check Radicale logs for errors:
sudo journalctl -u radicale
- Regularly update Modoboa and its extensions:
pip install --upgrade modoboa-radicale
- Check Radicale logs for errors:
By following these steps, you’ll successfully integrate and configure modoboa-radicale
with your Modoboa server, enabling seamless calendar and contact synchronization.
Conclusion
You now know how to install and run Modoboa email server on Debian VPS. Additionally, you have followed initial configuration steps and modoboa-webmail and modoboa-radicale integrations.
Provide your feedback in the comments below!