This repository contains the needed "infrastructure as code" to set up a Mail-in-a-Box. If you follow these instructions, it will
- Create a Digital Ocean Droplet as virtual machine for the Mail-In-A-Box
- Create a S3 Bucket for storing the Backups
- Install Mail-In-A-Box on the Droplet
After following the instructions, you have your own mailserver and cloud with automatic backups to the S3 Bucket :)
This is not a "one-button-click" solution for setting up your Mail-In-A-Box
- You should have an idea what a Mail-In-A-Box is. If not, check out the official website: mailinabox.email
- You should be familiar with the concept of infrastructure as code, more specifically you should know what OpenTofu/terraform is
- You should have an idea, what a S3 Bucket is and a Digital Ocean Droplet
- You must have a Digital Ocean account
- You must have an AWS account
I created this repo to create a new Mail-In-A-Box, because my old one was still running Ubuntu 18.
- Initialize opentofu by running
tofu init
- Copy
terraform.tfvars.template
toterraform.tfvars
and set required variables (this file gets git-ignored, so you do not accidentally commit secrets)- the scripts located at
scripts/
can help you find some of the values you need
- the scripts located at
- Execute
tofu plan
and check if you agree what it wants to do - Execute
tofu apply
to set everything up - Wait 15 seconds and use the output of
tofu output miab_droplet_ssh_instructions
tossh
into the droplet - Execute
tail -f /var/log/cloud-init-output.log
inside of the droplet and watch the output.- If the mailinabox installation fails because the ip-address is on a spam list
- destroy the droplet again by executing
tofu destroy -target digitalocean_droplet.miab_server
on your machine - Re-execute
tofu plan
andtofu apply
so that the droplet gets recreated, and you get a new ip-address - Re-watch the logs and repeat until the mailinabox setup was able to complete
- destroy the droplet again by executing
- If the mailinabox installation fails because the ip-address is on a spam list
- Log into the box by using the URL that you get when executing
tofu output miab_login
- E-Mail: Execute
tofu output miab_first_admin_user_email_address
to get the value - Password: Execute
tofu output miab_first_admin_user_password
to get the value
- E-Mail: Execute
- Configure the backup to the created S3 bucket by setting the following values in the form at
System > Backup Status
- Backup to:
S3
- S3 Region: Execute
tofu output backup_s3_bucket_region
to get the value - S3 Host: Execute
tofu output backup_s3_bucket_host
to get the value - S3 Region Name: Leave empty
- S3 Bucket & Path: Execute
tofu output backup_s3_bucket_path
to get the value (remove the/
at the end) - S3 Access Key: Execute
tofu output backup_s3_bucket_access-key
to get the value - S3 Secret Access Key: Execute
tofu output backup_s3_bucket_secret-key
to get the value - Retention Days: Set this value as you wish to
- Backup to:
- Execute first backup by executing
sudo /mailinabox/management/backup.py
inside of the droplet - Copy the file
/home/user-data/backup/secret_key.txt
from the machine to a secure location by executing the commandtofu output miab_copy_backup_file_command
to get thescp
command you have to execute. Execute that command. - Set the Nameservers of your domain to the domains you get when you execute
tofu output backup_s3_bucket_path
- Again, log into the admin panel of your box by using the URL from the
tofu output miab_login
command. Check the status of your box by navigating toSystem > Status Checks
- Automatically configure Backup to S3
- Let user configure timezone and locale in
tfvars
- Set correct text encoding, so that they are no issues with
f�r
orzus�tzliche