From 3dc86cf46bcfb3986093dfe2a8d587605f03c299 Mon Sep 17 00:00:00 2001 From: allan Date: Fri, 19 Dec 2025 14:58:06 +0100 Subject: [PATCH] latest commit --- LICENSE | 21 +++++++ README.md | 164 +++++++++++++++++++++++++++++++++++++++++++++++++ last-tested | 4 ++ postfixinstall | 108 ++++++++++++++++++++++++++++++++ 4 files changed, 297 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 last-tested create mode 100755 postfixinstall diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3eaaa81 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Allan Christensen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..46cf67d --- /dev/null +++ b/README.md @@ -0,0 +1,164 @@ +# Postfix for Ubuntu 24.04 Server +[![OS](https://img.shields.io/badge/ubuntu-24.04-E95420)](#) +[![Shell](https://img.shields.io/badge/shell-bash-121011)](#) +[![MailServer](https://img.shields.io/badge/server-postfix-8B1E3F)](#) +[![License](https://img.shields.io/badge/License-MIT-green)](./LICENSE) + +Install Postfix on Ubuntu 24.04 server. + +This is not a demo and not an experiment. +No installer prompts, no guesswork — reliable and repeatable mail server deployment. + +## Why this installer exists +Postfix itself is simple. The interactive installer is not. This avoids incorrect menu selections. + +## What this installer does +✔ Fully non-interactive setup +✔ Optional mailutils integration +✔ Runs as a proper MTA +✔ Suitable for relay + local delivery +✔ Consistent, repeatable configuration + +## What this installer does *NOT* do +It won’t stop you from running the script without reading the documentation like there’s no tomorrow. +Skip the README, and whatever happens next is your headache, not a bug report. + +--- + +## 1. Prepare the system + +``` +sudo apt update -y +``` + +## 2. Download the installer + +``` +git clone https://git.x-files.dk/mail/postfix-ubuntu.git +``` + +``` +cd postfix-ubuntu +``` + +## 3. Run the installer + +``` +sudo ./postfixinstall -m +``` + +### Flags + +| Option | Meaning | +|---|---| +| `-m yes` | Install Postfix + Mailutils | +| `-m no` | Install only Postfix | + +Examples: + +``` +sudo ./postfixinstall -m yes # Postfix + Mailutils +sudo ./postfixinstall -m no # Pure Postfix only +``` + +--- + +## 2. Service Status + +``` +systemctl status postfix +systemctl enable postfix +``` + +Send test mail (if Mailutils installed): + +``` +echo "Postfix is alive" | mail -s "Test" root@localhost +``` + +--- + +## 3. Default Configuration + +Main config file: + +``` +/etc/postfix/main.cf +``` + +Common values: + +``` +myhostname = mail.example.com +myorigin = /etc/mailname +mydestination = localhost, $myhostname +relayhost = +inet_interfaces = all +``` + +Reload config: + +``` +sudo systemctl reload postfix +``` + +--- + +## 4. TLS + Certbot Integration (optional) + +Recommended additions: + +``` +smtp_tls_security_level = may +smtp_tls_loglevel = 1 +smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt +``` + +Apply: + +``` +sudo systemctl reload postfix +``` + +--- + +## 5. Useful Commands + +List queue: + +``` +mailq +``` + +Flush queue: + +``` +postfix flush +``` + +Logs: + +``` +journalctl -u postfix -f +``` + +Control service: + +``` +systemctl stop postfix +systemctl start postfix +systemctl reload postfix +``` + +--- + +### More Information + +More guides and documentation can be found on [wiki.x-files.dk](https://wiki.x-files.dk) + +--- + +### License +Licensed under the [MIT License](./LICENSE). + +--- diff --git a/last-tested b/last-tested new file mode 100644 index 0000000..02156f4 --- /dev/null +++ b/last-tested @@ -0,0 +1,4 @@ +------------------------------------ +Last tested: 19-12-2025 (DD-MM-YYYY) +Environment: Ubuntu Server 24.04 LTS +------------------------------------ diff --git a/postfixinstall b/postfixinstall new file mode 100755 index 0000000..0112926 --- /dev/null +++ b/postfixinstall @@ -0,0 +1,108 @@ +#!/usr/bin/env bash + +# Author : Allan Christensen +# First Created : 17-10-2020 (DD-MM-YYYY) +# Description : Installs Postfix and optionally Mailutils on Ubuntu 24.04 +# License : MIT License + +# +# Are we root +# +if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo "" ; exit ; fi + +# +# Define variables and functions +# +install_utils="no" + +# +# Function to check if a service is already running +# +serviceyes () { printf "\n%s" $service ; printf " is already running cannot continue...\n\n"; } +servicealive () { status=$(systemctl is-active $service); if [[ "$status" == "active" ]]; then serviceyes ; exit 1; fi; } + +# +# Usage function +# +usage() { + printf "\nUsage:\n" + printf " sudo ./postfixinstall [-m yes|no]\n\n" + printf "Options:\n" + printf " -m Install Mailutils (defaults to no)\n" + printf " -h Show this help message\n\n" + printf "Examples:\n" + printf " sudo ./postfixinstall # install Postfix only\n" + printf " sudo ./postfixinstall -m yes # install Postfix + Mailutils\n\n" + exit 1 +} + +# +# If Postfix is already running then die +# +service="postfix" ; servicealive + +# +# Let's go +# +clear + +# +# Parse options +# +while getopts ":m:h" opt; do + case "${opt}" in + m) + arg="${OPTARG}" + if [[ -z "$arg" ]]; then + printf "\nOption -m requires an argument (yes/no).\n" + usage + fi + case "${arg,,}" in + y|yes) install_utils="yes" ;; + n|no) install_utils="no" ;; + *) usage ;; + esac + ;; + h) + usage + ;; + :) + printf "\nOption -%s requires an argument (yes/no).\n" "$OPTARG" + usage + ;; + \?) + printf "\nInvalid option: -%s\n" "$OPTARG" + usage + ;; + esac +done + +# +# Require -m flag +# +if [[ "$OPTIND" -eq 1 ]]; then + printf "\nMissing required option: -m \n" + usage +fi + +# +# Install Postfix (non-interactive) and backup main.cf +# +printf "\nInstalling Postfix...\n" +DEBIAN_FRONTEND=noninteractive apt-get install -y postfix >/dev/null 2>&1 +[[ -f /etc/postfix/main.cf ]] && cp -p /etc/postfix/main.cf /etc/postfix/main.cf.bak.$(date +%d-%m-%Y-%H%M%S) +systemctl enable postfix >/dev/null 2>&1 && systemctl restart postfix + +# +# Optionally install Mailutils +# +if [[ "$install_utils" == "yes" ]]; then apt-get install -y mailutils >/dev/null 2>&1 ; fi + +# +# All done +# +printf "\nAll Done...\n" + +# +# End of script +#