### Example Mail Configuration (YAML) Source: https://mailu.io/2024.06/cli.html This is an example of a `mail-config.yml` file structure, defining domains, users, aliases, and relays. ```yaml domain: - name: example.com alternatives: - alternative.example.com user: - email: foo@example.com password_hash: '$2b$12$...' hash_scheme: MD5-CRYPT alias: - email: alias1@example.com destination: - user1@example.com - user2@example.com relay: - name: relay.example.com comment: test smtp: mx.example.com ``` -------------------------------- ### Run Mailu Web Administration with Custom Database Source: https://mailu.io/2024.06/contributors/environment.html Start the development server using a specific database file by setting the DEV_DB environment variable. ```bash DEV_DB="/path/to/dev.db" ./run_dev.sh ``` -------------------------------- ### Configure PostgreSQL pg_hba.conf Source: https://mailu.io/2024.06/database.html An example line to add to the pg_hba.conf file to allow the Mailu user to connect to the Mailu database from the specified Mailu host. ```text host mailu mailu /32 md5 ``` -------------------------------- ### Install Packages Inside a Mailu Container Source: https://mailu.io/2024.06/contributors/environment.html If you need to install additional packages for debugging within a container, use `docker compose exec apk add --no-cache `. This example adds `package-name` to the admin container. ```bash docker compose exec admin apk add --no-cache package-name ``` -------------------------------- ### Install IMAP Dependencies for Nextcloud Source: https://mailu.io/2024.06/faq.html This command installs the necessary libraries (libc-client-dev, libkrb5-dev) and configures the PHP IMAP extension for Nextcloud, enabling IMAP authentication for older versions. ```bash apt-get update \ && apt-get install -y libc-client-dev libkrb5-dev \ && rm -rf /var/lib/apt/lists/* \ && docker-php-ext-configure imap --with-kerberos --with-imap-ssl \ && docker-php-ext-install imap ``` -------------------------------- ### Start a Shell Inside a Mailu Container Source: https://mailu.io/2024.06/contributors/environment.html For debugging purposes, you can start an interactive shell session within a container using `docker compose exec sh`. This example opens a shell in the admin container. ```bash docker compose exec admin sh ``` -------------------------------- ### Start Mailu service Source: https://mailu.io/2024.06/compose/setup.html Starts the Mailu services in detached mode using Docker Compose. Ensure you are in the Mailu directory before running this command. ```bash docker compose up -d ``` -------------------------------- ### Check Docker and Docker Compose Versions Source: https://mailu.io/2024.06/compose/requirements.html Verify that Docker and Docker Compose are installed and running correctly by checking their versions. This ensures compatibility with Mailu. ```bash $ docker version Client: Docker Engine - Community Version: 20.10.22 API version: 1.41 Go version: go1.18.9 Git commit: 3a2c30b Built: Thu Dec 15 22:27:03 2022 OS/Arch: linux/arm64 Context: default Experimental: true Server: Docker Engine - Community Engine: Version: 20.10.22 API version: 1.41 (minimum version 1.12) Go version: go1.18.9 Git commit: 42c8b31 Built: Thu Dec 15 22:25:25 2022 OS/Arch: linux/arm64 Experimental: false containerd: Version: 1.6.14 GitCommit: 9ba4b250366a5ddde94bb7c9d1def331423aa323 runc: Version: 1.1.4 GitCommit: v1.1.4-0-g5fd4c4d docker-init: Version: 0.19.0 GitCommit: de40ad0 $ docker compose version Docker Compose version v2.14.1 ``` -------------------------------- ### Run Mailu Containers with Docker Compose Source: https://mailu.io/2024.06/contributors/environment.html After building the images, navigate to your project directory and ensure the `VERSION` in `.env` matches your build version. Then, use `docker compose up -d` to start the containers in detached mode. ```bash docker compose up -d ``` -------------------------------- ### Configure Fail2Ban Service to Start After Docker Source: https://mailu.io/2024.06/faq.html Create a systemd override for the Fail2Ban service to ensure it starts after the Docker service. This is crucial for correct iptables and ipset rule application. ```bash sudo systemctl edit fail2ban ``` ```ini [Unit] After=docker.service ``` ```bash sudo systemctl restart fail2ban ``` -------------------------------- ### Upgrade Mailu using Docker Compose Source: https://mailu.io/2024.06/releases.html Commands to pull the latest Mailu images, stop the current services, and start the updated ones. Ensure you have backups before proceeding. ```bash docker compose pull docker compose down --remove-orphans docker compose up -d ``` -------------------------------- ### Clone Mailu repository and create a new branch Source: https://mailu.io/2024.06/contributors/environment.html Clone your Mailu fork, navigate into the directory, set the upstream remote, and create a new branch for your work. Always start new branches from 'master'. ```bash git clone https://github.com//Mailu.git cd Mailu git remote add upstream https://github.com/Mailu/Mailu.git git checkout -b fix-something master ``` -------------------------------- ### Build and Run Mailu Documentation Server Source: https://mailu.io/2024.06/contributors/environment.html Build a Docker image for the documentation and run it as a container, exposing the server on port 8080. ```bash cd docker build -t docs docs docker run -p 127.0.0.1:8080:80 docs ``` -------------------------------- ### Run Mailu Web Administration Development Server Source: https://mailu.io/2024.06/contributors/environment.html Navigate to the admin core directory and run the development script. This sets up a local webserver listening on port 8080. ```bash cd core/admin ./run_dev.sh pip install -r requirements.txt ``` -------------------------------- ### Example Spam Score Email Header Source: https://mailu.io/2024.06/antispam.html This is an example of an email header showing a spam score of 14, indicated by X-Spamd-Bar and X-Spam-Level. ```text X-Spamd-Bar: ++++++++++++++ X-Spam-Level: ************** Authentication-Results: test.mailu.io; dkim=pass header.d=example.com header.s=mailing header.b=ABCDE; dkim=pass header.d=example.com header.s=mailing header.b=ABCDE; dmarc=pass (policy=none) header.from=eventim.de; spf=pass (test.mailu.io: domain of return@example.com designates 11.22.33.44 as permitted sender) smtp.mailfrom=return@example.com X-Spam: Yes ``` -------------------------------- ### Import Mailu Configuration Source: https://mailu.io/2024.06/database.html After initializing and upgrading the database, import the previously exported configuration. The -v flag enables verbose output. ```bash flask mailu config-import -v < /data/mail-config.yml ``` -------------------------------- ### Set up External PostgreSQL for Mailu Source: https://mailu.io/2024.06/database.html Shell commands and SQL statements to create a user, set a password, create a database owned by the user, and enable the citext extension for Mailu in PostgreSQL. ```bash $ sudo su - postgres $ psql psql (10.6) Type "help" for help. postgres=# create user mailu; CREATE ROLE postgres=# alter user mailu password 'my_secure_pass'; ALTER ROLE postgres=# create database mailu owner mailu; CREATE DATABASE postgres=# \c mailu You are now connected to database "mailu" as user "postgres". mailu=# create extension citext; CREATE EXTENSION mailu=# \q ``` -------------------------------- ### Correctly Copy Let's Encrypt Certificates Source: https://mailu.io/2024.06/faq.html Demonstrates the correct method for copying Let's Encrypt certificates to the Mailu certs directory, avoiding the pitfalls of copying symlinks. ```bash cp -r /etc/letsencrypt/live/domain.com /mailu/certs ``` ```bash mkdir -p /mailu/certs cp /etc/letsencrypt/live/domain.com/privkey.pem /mailu/certs/key.pem cp /etc/letsencrypt/live/domain.com/fullchain.pem /mailu/certs/cert.pem ``` -------------------------------- ### Set up External MySQL/MariaDB for Mailu Source: https://mailu.io/2024.06/database.html SQL commands to create a database, user, and grant necessary privileges for Mailu to use an external MySQL or MariaDB server. ```sql mysql> CREATE DATABASE mailu; mysql> CREATE USER `mailu`@`%` IDENTIFIED WITH mysql_native_password BY `my-strong-password-here`; mysql> GRANT ALL PRIVILEGES ON mailu.* TO 'mailu'@'%'; mysql> FLUSH PRIVILEGES; ``` -------------------------------- ### Initialize and Upgrade Mailu Database Source: https://mailu.io/2024.06/database.html These commands are executed within the admin container to initialize the new database back-end and upgrade it to the current Mailu schema. ```bash docker exec -i $(docker compose ps -q admin) bash ``` ```bash flask mailu db init ``` ```bash flask mailu db upgrade ``` -------------------------------- ### Remove Exim MTA on Debian Source: https://mailu.io/2024.06/compose/requirements.html Before installing Mailu, remove the default Exim MTA to avoid port conflicts. This command purges Exim and its base configuration. ```bash apt-get autoremove --purge exim4 exim4-base ``` -------------------------------- ### Check Mailu Front and Letsencrypt Logs Source: https://mailu.io/2024.06/faq.html View logs for the 'front' service and the Letsencrypt log file within the 'front' container to diagnose TLS/Let's Encrypt issues. Use 'less -R' for readable output. ```bash docker compose logs front | less -R ``` ```bash docker compose exec front less /var/log/letsencrypt/letsencrypt.log ``` -------------------------------- ### Create Mailu admin user Source: https://mailu.io/2024.06/compose/setup.html Manually creates an administrator account for Mailu. Replace 'me@example.net' and 'password' with your desired username and a strong password. ```bash docker compose exec admin flask mailu admin me example.net 'password' ``` -------------------------------- ### Batch Column Alteration and Data Conversion in Migration Script Source: https://mailu.io/2024.06/contributors/database.html Example of converting data and altering a column with a default value using batch operations in SQLite migrations. ```python def upgrade(): # spam_threshold is a X/15 based value, we're converting it to percent. for user in User.query.all(): user.spam_threshold = int(100. * float(user.spam_threshold or 0.) / 15.) db.session.commit() # set default to 80% with op.batch_alter_table('user') as batch: batch.alter_column('spam_threshold', default=80.) ``` -------------------------------- ### Build and Push Mailu Images to Docker Hub Source: https://mailu.io/2024.06/contributors/environment.html Before pushing images, log in to Docker Hub and set the `DOCKER_ORG`, `MAILU_VERSION`, and `MAILU_PINNED_VERSION` environment variables. Use `--push` to upload the built images. ```bash docker login Username: Foo Password: Bar export DOCKER_ORG="Foo" export MAILU_VERSION="feat-extra-app" export MAILU_PINNED_VERSION="feat-extra-app" docker buildx bake -f tests/build.hcl --push ``` -------------------------------- ### Display Help for config-import Command Source: https://mailu.io/2024.06/cli.html Use this command to view the help message and available options for the `mailu config-import` command. ```bash $ docker compose exec -T admin flask mailu config-import --help ``` -------------------------------- ### Get network interface information Source: https://mailu.io/2024.06/compose/setup.html Displays network interface details, useful for identifying public IP addresses required for Mailu's bind address configuration. ```bash [root@mailu ~]$ ifconfig eth0 eth0: flags=4163 mtu 1500 inet 125.189.138.127 netmask 255.255.255.0 broadcast 5.189.138.255 inet6 fd21:aab2:717c:cc5a::1 prefixlen 64 scopeid 0x0 inet6 fe2f:2a73:43a8:7a1b::1 prefixlen 64 scopeid 0x20 ether 00:50:56:3c:b2:23 txqueuelen 1000 (Ethernet) RX packets 174866612 bytes 127773819607 (118.9 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 19905110 bytes 2191519656 (2.0 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ``` -------------------------------- ### Automatic Admin Account Creation with Environment Variables Source: https://mailu.io/2024.06/configuration.html Define these environment variables to automatically create an admin user account upon deployment. It is recommended to use `ifmissing` or `update` for `INITIAL_ADMIN_MODE` to avoid errors on restarts. ```bash INITIAL_ADMIN_ACCOUNT=me INITIAL_ADMIN_DOMAIN=example.net INITIAL_ADMIN_PW=password INITIAL_ADMIN_MODE=ifmissing ``` -------------------------------- ### Execute Command Inside a Mailu Container Source: https://mailu.io/2024.06/contributors/environment.html To run a command within a specific Mailu container, use `docker compose exec `. This example lists files in the admin container's root directory. ```bash docker compose exec admin ls -lah / ``` -------------------------------- ### Create Mailu data directory Source: https://mailu.io/2024.06/compose/setup.html Creates the directory where Mailu will store its persistent data and navigates into it. This is the first step in preparing the environment. ```bash mkdir /mailu cd /mailu ``` -------------------------------- ### Load Dump into New PostgreSQL Instance Source: https://mailu.io/2024.06/database.html Executes a command within the newly created PostgreSQL container to load the previously created SQL dump. This populates the new database with existing data. ```bash docker compose -f docker compose-postgresql.yml exec database /bin/bash cat /dump/backup_db.sql | psql -h localhost -p 5432 -U mailu exit ``` -------------------------------- ### Build All Mailu Images Source: https://mailu.io/2024.06/contributors/environment.html Use this command to build all Mailu Docker images from the `build.hcl` file. Ensure you are in the Mailu directory after cloning the repository. ```bash cd Mailu docker buildx bake -f tests/build.hcl --load ``` -------------------------------- ### Full YAML Template for Mailu Configuration Source: https://mailu.io/2024.06/cli.html A comprehensive YAML template illustrating all possible parameters for configuring domains, users, aliases, and relays in Mailu. ```yaml domain: - name: example.com alternatives: - alternative.tld comment: '' dkim_key: '' max_aliases: -1 max_quota_bytes: 0 max_users: -1 signup_enabled: false user: - email: postmaster@example.com comment: '' displayed_name: 'Postmaster' enable_imap: true enable_pop: false enabled: true fetches: - id: 1 comment: 'test fetch' error: null host: other.example.com keep: true last_check: '2020-12-29T17:09:48.200179' password: 'secret' hash_password: true port: 993 protocol: imap tls: true username: fetch-user forward_destination: - address@remote.example.com forward_enabled: true forward_keep: true global_admin: true manager_of: - example.com password: '$2b$12$' hash_password: true quota_bytes: 1000000000 reply_body: '' reply_enabled: false reply_enddate: '2999-12-31' reply_startdate: '1900-01-01' reply_subject: '' spam_enabled: true spam_mark_as_read: true spam_threshold: 80 tokens: - id: 1 comment: email-client ip: 192.168.1.1 password: '$5$rounds=1$' alias: - email: email@example.com comment: '' destination: - address@example.com wildcard: false relay: - name: relay.example.com comment: '' smtp: mx.example.com ``` -------------------------------- ### Import Configuration from File via Stdin Source: https://mailu.io/2024.06/cli.html Import configuration data from a YAML file using standard input. Ensure the `-T` option is used with `docker compose exec` for correct stdin handling. ```bash docker compose exec -T admin flask mailu config-import -nv < mail-config.yml ``` -------------------------------- ### Upgrade Local Database Source: https://mailu.io/2024.06/contributors/database.html Apply the generated migration scripts to your local database. ```bash flask db upgrade ``` -------------------------------- ### Create Mailu User Source: https://mailu.io/2024.06/cli.html Use this command to create a new Mailu user. Specify the username, domain, and the user's password. ```bash docker compose exec admin flask mailu user myuser example.net 'password123' ``` -------------------------------- ### Generate Database Migration Script Source: https://mailu.io/2024.06/contributors/database.html Run this command after modifying database models to create a new migration script. ```bash flask db migrate ``` -------------------------------- ### Learn Ham Messages with rspamc Source: https://mailu.io/2024.06/antispam.html Use these commands to learn existing emails in a specified folder as ham (not spam) using rspamc. Ensure the Rspamd service is accessible. ```bash rspamc -h antispam:11334 -P mailu -f 13 fuzzy_add /mail/user\@example.com/.Ham_Learn/cur/ ``` ```bash rspamc -h antispam:11334 -P mailu learn_ham /mail/user\@example.com/.Ham_Learn/cur/ ``` -------------------------------- ### user Source: https://mailu.io/2024.06/cli.html Creates or updates a user account. ```APIDOC ## user Creates or updates a user account. ### Usage ```bash docker compose exec admin flask mailu user ``` ### Example ```bash docker compose exec admin flask mailu user myuser example.net 'password123' ``` ``` -------------------------------- ### Enabling Docker's Experimental IPv6 Support Source: https://mailu.io/2024.06/faq.html Configure Docker's daemon.json to enable experimental IPv6 support, including fixed IPv6 CIDR and ip6tables. ```json { "userland-proxy": false, "ipv6": true, "experimental": true, "fixed-cidr-v6": "fd00:1234:abcd::/48", "ip6tables": true } ``` -------------------------------- ### Import Mailu User with Hashed Password Source: https://mailu.io/2024.06/cli.html This command is useful for migrating users from other systems where only the password hash is known. It imports a user with a pre-computed password hash and its corresponding algorithm. ```bash docker compose run --rm admin flask mailu user-import myuser example.net '$6$51ebe0cb9f1dab48effa2a0ad8660cb489b445936b9ffd812a0b8f46bca66dd549fea530ce' 'SHA512-CRYPT' ``` -------------------------------- ### Commit changes and push to origin Source: https://mailu.io/2024.06/contributors/environment.html Stage all changes, commit them with a message, and push the branch to your GitHub repository. This prepares your changes for a pull request. ```bash git commit -a #Enter commit message in editor, save and close. git push --set-upstream origin fix-something ``` -------------------------------- ### Configure Mail Server Hostname (A Record) Source: https://mailu.io/2024.06/dns.html Set up an A record to point your mail server's hostname to its public IP address. This is essential for other mail servers to find your server. ```dns mail.mydomain.com. IN A a.b.c.d ``` -------------------------------- ### Create PostgreSQL Dump Source: https://mailu.io/2024.06/database.html Executes a command within the Mailu database container to create a SQL dump of the current PostgreSQL database. Ensure Mailu is stopped and only the database container is running. ```bash docker compose -p mailu exec database /bin/bash pg_dump -h database -p 5432 -U mailu > /backup/backup_db.sql exit ``` -------------------------------- ### Learn Ham Messages with rspamc Source: https://mailu.io/2024.06/faq.html Use `rspamc` within the Dovecot container to learn existing messages as ham. Specify the antispam host, password, and the path to the folder containing ham messages. ```bash rspamc -h antispam:11334 -P mailu -f 13 fuzzy_add /mail/user@example.com/.Ham_Learn/cur/ rspamc -h antispam:11334 -P mailu learn_ham /mail/user@example.com/.Ham_Learn/cur/ ``` -------------------------------- ### Update Mailu Configuration from YAML Source: https://mailu.io/2024.06/cli.html This command imports users and aliases in bulk and synchronizes database entries with an external YAML template. Use --delete-objects to remove entries not present in the YAML. ```bash cat mail-config.yml | docker compose exec -T admin flask mailu config-update --delete-objects ``` ```yaml users: - localpart: foo domain: example.com password_hash: klkjhumnzxcjkajahsdqweqqwr alias: - localpart: alias1 domain: example.com destination: "user1@example.com,user2@example.com" ``` -------------------------------- ### Configure Mailu Database URI Source: https://mailu.io/2024.06/database.html Appends the database connection string to the `mailu.env` file, specifying the PostgreSQL connection details for Mailu to use. ```env SQLALCHEMY_DATABASE_URI=postgresql://mailu:mailu@database/mailu ``` -------------------------------- ### Mailu CLI Commands Overview Source: https://mailu.io/2024.06/cli.html The Mailu command-line interface provides several commands for managing domains, users, aliases, and configuration. These commands are typically executed via `docker compose exec admin flask mailu ...` or `docker compose run --rm admin flask mailu ...`. ```APIDOC ## Mailu CLI Commands Managing domains, users and aliases can be done from CLI using the commands: * `alias` * `alias-delete` * `domain` * `password` * `user` * `user-import` * `user-delete` * `config-update` * `config-export` * `config-import` ``` -------------------------------- ### Configure Polite and Turtle Queues for Slow Delivery Source: https://mailu.io/2024.06/faq.html Use this configuration to manage email delivery speed for specific domains by assigning them to 'polite' or 'turtle' queues. Restart the smtp container for changes to take effect. ```bash yahoo.com polite: orange.fr turtle: ``` -------------------------------- ### Configure Nextcloud External User Backend (IMAP - Older Versions) Source: https://mailu.io/2024.06/faq.html This configuration is for Nextcloud versions 14 and older. It sets up the IMAP user backend in config/config.php, specifying the IMAP server and domain for authentication. ```php array( array( 'class' => 'OC_User_IMAP', 'arguments' => array( '{imap.example.com:993/imap/ssl}', 'example.com' ), ), ), ``` -------------------------------- ### Export Mailu Configuration Source: https://mailu.io/2024.06/database.html Use this command to export Mailu's configuration, including secrets, to a YAML file. This is the first step in migrating to a different database back-end. ```bash docker compose exec admin flask mailu config-export --secrets --output-file /data/mail-config.yml ``` -------------------------------- ### Configure Nextcloud External User Backend (IMAP) Source: https://mailu.io/2024.06/faq.html Use this configuration in Nextcloud's config/config.php to integrate with Mailu's IMAP for user authentication. It specifies the IMAP server details and the domain to be used for login. ```php array( array( 'class' => 'OC_User_IMAP', 'arguments' => array( '127.0.0.1', 993, 'ssl', 'example.com', true, false ), ), ), ``` -------------------------------- ### Configure Roundcube Spellchecker (Aspell) Source: https://mailu.io/2024.06/faq.html Enable additional languages for Roundcube's spellchecker by placing aspell dictionaries in the specified directory and updating the configuration. ```php $config['spellcheck_languages'] = array('en'=>'English', ...); ``` -------------------------------- ### Learn Spam Messages with rspamc Source: https://mailu.io/2024.06/antispam.html Use these commands to learn existing emails in a specified folder as spam using rspamc. Ensure the Rspamd service is accessible. ```bash rspamc -h antispam:11334 -P mailu -f 11 fuzzy_add /mail/user\@example.com/.Spam_Learn/cur/ ``` ```bash rspamc -h antispam:11334 -P mailu learn_spam /mail/user\@example.com/.Spam_Learn/cur/ ``` -------------------------------- ### Create Mailu Alias Source: https://mailu.io/2024.06/cli.html Use this command to create a new email alias. Specify the alias name, domain, and the destination email addresses. ```bash docker compose exec admin flask mailu alias foo example.net "mail1@example.com,mail2@example.com" ``` -------------------------------- ### user-import Source: https://mailu.io/2024.06/cli.html Imports users, useful for migrating users from other systems where only the password hash is known. ```APIDOC ## user-import Imports users with a pre-hashed password. ### Usage ```bash docker compose run --rm admin flask mailu user-import ``` ### Example ```bash docker compose run --rm admin flask mailu user-import myuser example.net '$6$51ebe0cb9f1dab48effa2a0ad8660cb489b445936b9ffd812a0b8f46bca66dd549fea530ce' 'SHA512-CRYPT' ``` ``` -------------------------------- ### Extract Translations with Babel Source: https://mailu.io/2024.06/contributors/memo.html Run this command to extract translatable strings from the Mailu codebase into a POT file. Ensure Babel syntax is used in your code. ```bash pybabel extract -F babel.cfg -k lazy_gettext -o messages.pot mailu ``` -------------------------------- ### Restart Mailu Containers Source: https://mailu.io/2024.06/faq.html Use this command to apply changes to environment variables in Mailu. A full down and up cycle is required, not just a container restart. ```bash docker compose down && \ docker compose up -d ``` -------------------------------- ### Test Pull Requests with Docker Compose Source: https://mailu.io/2024.06/contributors/environment.html To test a specific pull request, set `DOCKER_ORG` and `MAILU_VERSION` to the PR tag. Then, pull the images and run the containers using `docker compose pull` and `docker compose up -d`. ```bash export DOCKER_ORG="ghcr.io/mailu" export MAILU_VERSION="pr-500" docker compose pull docker compose up -d ``` -------------------------------- ### Configure Mailu Front Container Logging for Fail2Ban Source: https://mailu.io/2024.06/faq.html Set the logging driver to journald and tag to mailu-front for the front container in your docker-compose file. This allows Fail2Ban to capture relevant logs. ```yaml logging: driver: journald options: tag: mailu-front ```