version 1

This commit is contained in:
2025-11-20 22:32:15 +01:00
commit e74a891919
23 changed files with 914 additions and 0 deletions

43
tools/add_mailuser.sh Executable file
View File

@@ -0,0 +1,43 @@
#!/usr/bin/env bash
set -euo pipefail
MAILSERVER_CONTAINER="mailserver"
PWGEN_CMD="pwgen -scn 32"
if [ $# -ne 1 -o $# -ne 2 ]
then
echo "Usage: $0 mail_address [password]"
exit 1
fi
EMAIL="$1"
PASSWORD="${2:-}"
if [ -z "$PASSWORD" ]
then
# Ensure pwgen exists
if ! command -v pwgen >/dev/null 2>&1; then
echo "ERROR: pwgen is not installed. Install with: sudo apt install pwgen"
exit 1
fi
# Generate a secure password
PASSWORD="$($PWGEN_CMD)"
fi
# Create the mailbox inside Docker-Mailserver (DMS hashes internally)
docker exec -i "$MAILSERVER_CONTAINER" setup email add "$EMAIL" "$PASSWORD"
echo
echo "=============================================="
echo "User added: $EMAIL"
echo
echo "Generated password (plaintext):"
echo " $PASSWORD"
echo
echo "This password is NOT stored in plaintext anywhere."
echo "Docker-Mailserver stored only a secure hash."
echo "=============================================="
echo
echo "Restart mailserver to apply changes:"
echo " docker compose restart mail"