Skip to content

Instantly share code, notes, and snippets.

@amanjuman
Last active January 21, 2024 09:51
Show Gist options
  • Save amanjuman/f71c881044bf5a2584356b0a97181459 to your computer and use it in GitHub Desktop.
Save amanjuman/f71c881044bf5a2584356b0a97181459 to your computer and use it in GitHub Desktop.
Postal Server Installation Script

Set Server Hostname

hostnamectl set-hostname fqdn.domain.tld

Install Docker

curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh
curl -SL https://github.com/docker/compose/releases/download/v2.24.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Install Required Packages

sudo apt install git curl jq net-tools mariadb-client -y

Clone Postal Server Repo

git clone https://postalserver.io/start/install /opt/postal/install
sudo ln -s /opt/postal/install/bin/postal /usr/bin/postal

Create MySQL Docker Container

docker run -d \
   --name postal-mariadb \
   -p 127.0.0.1:3306:3306 \
   --restart always \
   -e MARIADB_DATABASE=postal \
   -e MARIADB_ROOT_PASSWORD=postal \
   mariadb

Create RabbitMQ Docker Container

docker run -d \
   --name postal-rabbitmq \
   -p 127.0.0.1:5672:5672 \
   --restart always \
   -e RABBITMQ_DEFAULT_USER=postal \
   -e RABBITMQ_DEFAULT_PASS=postal \
   -e RABBITMQ_DEFAULT_VHOST=postal \
   rabbitmq:3.8

Generate Postal Configuration

postal bootstrap fqdn.domain.tld

Modify Configuration File

sudo nano /opt/postal/config/postal.yml

Create Caddy Docker Container

docker run -d \
   --name postal-caddy \
   --restart always \
   --network host \
   -v /opt/postal/config/Caddyfile:/etc/caddy/Caddyfile \
   -v /opt/postal/caddy-data:/data \
   caddy

Build Postal Server

postal initialize

Create Admin User

postal make-user

Start Postal Server

postal start

Generate Default DKIM

postal default-dkim-record

Uninstall and Clean Postal Server

docker stop $(docker ps -q --filter "name=postal-") && docker rm $(docker ps -aq --filter "name=postal-")
docker system prune -a
rm -rf /opt/postal /usr/bin/postal

Enable TLS

cp /opt/postal/caddy-data/caddy/certificates/acme-v02.api.letsencrypt.org-directory/fqdn.domain.tld/fqdn.domain.tld.crt /opt/postal/config/
cp /opt/postal/caddy-data/caddy/certificates/acme-v02.api.letsencrypt.org-directory/fqdn.domain.tld/fqdn.domain.tld.key /opt/postal/config/

Certificate Permission

sudo chmod 644 /opt/postal/config/fqdn.domain.tld.crt /opt/postal/config/fqdn.domain.tld.key

Ref: https://gist.github.com/amanjuman/14c492b3bbb152426809491e9ca67453

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment