Installing Mail-in-a-Box Locally for Development

Hi Mail-in-a-Box Maintainers,

I’m working on a project that involves making modifications to the Mail-in-a-Box (MiaB) login system to integrate it with other applications. I’d like to install MiaB on my local machine to make and test these changes.

I’ve reviewed the documentation, but I didn’t see any mention of whether MiaB can be safely installed and run on a local machine (such as a laptop) without risking any system instability or conflicts. Could you let me know if it’s possible to install MiaB locally for development purposes, and if there are any precautions I should take to avoid bricking my machine?

I don’t need to send or receive mail in this setup, just modify the login system.

Thanks in advance for your help!

Best regards,
Luey.

I would not install Mail-in-a-Box on a machine that you use for something else.

The best way is to use the included Vagrantfile to use a Vagrant-managed VM.

1 Like

Thanks very much for the quick response. Will do just that.

I cannot seem to find the files you speak of. Please can you show me where they are?

Edit: never mind. Saw it in the root dir. Browsing from mobile so i needed to click see more.

1 Like

Hi there everyone.

I read a lot about vagrant and virtual machines throughout yesterday.
I have some experience with VMWare but not so much virtualbox or vagrant.

Please can anyone help me with guidance on how to install MiaB locally using vagrant?
My current local dev environment OS is Ubuntu 22.04 LTS.

I do know VM’s and vagrant is out of scope of this project but given this is a use case where another person may need to setup MiaB locally to tinker with it, please consider offering help and insight for setting MiaB locally using a VM and Vagrant on Ubuntu. Thank you very much for your help and the time.

EDIT: I was able to install a VM and vagrant. But I get the following log in my terminal when I run vagrant up:

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'ubuntu/jammy64' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'ubuntu/jammy64'
    default: URL: https://vagrantcloud.com/ubuntu/jammy64
==> default: Adding box 'ubuntu/jammy64' (v20240912.0.0) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/ubuntu/boxes/jammy64/versions/20240912.0.0/providers/virtualbox/unknown/vagrant.box
==> default: Box download is resuming from prior download progress
Download redirected to host: cloud-images.ubuntu.com
==> default: Successfully added box 'ubuntu/jammy64' (v20240912.0.0) for 'virtualbox'!
==> default: Importing base box 'ubuntu/jammy64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/jammy64' version '20240912.0.0' is up to date...
==> default: Setting the name of the VM: mailinabox_default_1727864062358_15694
Vagrant is currently configured to create VirtualBox synced folders with
the `SharedFoldersEnableSymlinksCreate` option enabled. If the Vagrant
guest is not trusted, you may want to disable this option. For more
information on this option, please refer to the VirtualBox manual:

  https://www.virtualbox.org/manual/ch04.html#sharedfolders

This option can be disabled globally with an environment variable:

  VAGRANT_DISABLE_VBOXSYMLINKCREATE=1

or on a per folder basis within the Vagrantfile:

  config.vm.synced_folder '/host/path', '/guest/path', SharedFoldersEnableSymlinksCreate: false
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "2d884e5b-73e5-42fe-a5ac-686fcd66cef6", "--type", "headless"]

Stderr: VBoxManage: error: VT-x is disabled in the BIOS for all CPU modes (VERR_VMX_MSR_ALL_VMX_DISABLED)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component ConsoleWrap, interface IConsole

After fixing the initial issues above, i now find myself unable to run vm because my residential IP is blacklisted. Again, i am not trying to send mail, just want the app up and running to tinker with the web interface for log in and log out. Here is the output in my console:

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'ubuntu/jammy64' version '20240912.0.0' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 6.0.0 r127566
    default: VirtualBox Version: 6.1
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /shared_home/biggest/apps/mailinabox
==> default: Running provisioner: shell...
    default: Running: inline script
    default: 
    default: Primary Hostname: mailinabox.lan
    default: Public IP Address: XXX.XXX.xxx.XXX
    default: Private IP Address: XXX.XXX.xxx.XXX
    default: Mail-in-a-Box Version: v70-4-g1699ab8
    default: 
    default: 
    default: The IP address XXX.XXX.xxx.XXX is listed in the Spamhaus Block List.
    default: See http://www.spamhaus.org/query/ip/XXX.XXX.xxx.XXX.
    default: 
    default: You will not be able to send mail using this machine, so setup
    default: cannot continue.
    default: 
    default: Associate a different IP address with this machine if possible.
    default: Many residential network IP addresses are listed, so Mail-in-a-Box
    default: typically cannot be used on a residential Internet connection.
    default: 
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

The file mailinabox/CONTRIBUTING.md at main · mail-in-a-box/mailinabox · GitHub has a blurb about dealing with this. It says:
“If you’re seeing an error message about your IP address being listed in the Spamhaus Block List, simply uncomment the export SKIP_NETWORK_CHECKS=1 line in Vagrantfile. It’s normal, you’re probably using a dynamic IP address assigned by your Internet provider–they’re almost all listed.”

Give that a try by updating the vagrant file and creating a new vagrant instance with that line uncommented.

Thanks for the feedback @dms .

I have done that and now have my MiaB running locally. i can ssh into it and whatnot.

Now the main thing i wanted was the web interface to show. Currently, I cannot access the web app on my localhost, the public IP or even the private IP.

I tried port forwarding in vagrant file but alas to no avail.
Below is the output from my console:

    default: Generating DNSSEC signing keys...
    default: Installing Postfix (SMTP server)...
    default: Installing Dovecot (IMAP server)...
    default: Creating new user database: /home/user-data/mail/users.sqlite
    default: Installing OpenDKIM/OpenDMARC...
    default: Installing SpamAssassin...
    default: Installing Nginx (web server)...
    default: Installing Roundcube (webmail)...
    default: Installing Nextcloud (contacts/calendar)...
    default: 
    default: Upgrading to Nextcloud version 26.0.13
    default: 
    default: Nextcloud is already latest version
    default: photos 2.2.0 disabled
    default: dashboard 7.6.0 disabled
    default: activity 2.18.0 disabled
    default: Installing Z-Push (Exchange/ActiveSync server)...
    default: Installing Mail-in-a-Box system management daemon...
    default: Installing Munin (system monitoring)...
    default: updated DNS: mailinabox.lan
    default: web updated
    default: 
    default: Creating a new administrative mail account for me@mailinabox.lan with password 12345678.
    default: 
    default: mail user added
    default: updated DNS: mailinabox.lan
    default: web updated
    default: 
    default: 
    default: -----------------------------------------------
    default: Mail-in-a-Box uses Let's Encrypt to provision free SSL/TLS certificates
    default: to enable HTTPS connections to your box. We're automatically
    default: agreeing you to their subscriber agreement. See https://letsencrypt.org.
    default: 
    default: Saving debug log to /var/log/letsencrypt/letsencrypt.log
    default: Account registered.
    default: 
    default: -----------------------------------------------
    default: 
    default: Your Mail-in-a-Box is running.
    default: 
    default: Please log in to the control panel for further instructions at:
    default: 
    default: https://197.210.84.202/admin
    default: 
    default: You will be alerted that the website has an invalid certificate. Check that
    default: the certificate fingerprint matches:
    default: 
    default: AA:1B:7C:9B:90:49:66:34:60:47:D6:F9:CA:A7:02:AE:AB:05:E5:F4:F8:A7:89:77:C8:19:F8:69:3F:42:3F:44
    default: 
    default: Then you can confirm the security exception and continue.
    default: 

Visiting the address I get the following page:

You can access the UI using the private IP address in the MiaB Vagrantfile on the line: config.vm.network. Default User/PW can be found in the CONTRIBUTING.md file.

If you have not changed that value, then you should be able to access it at https://192.168.56.4/admin.

1 Like

Thanks @dms.

When I try to access that, the url in my browser shows https://mailinabox.lan/admin

And the UI does not show. Here is my vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/jammy64"

  # Network config: Since it's a mail server, the machine must be connected
  # to the public web. However, we currently don't want to expose SSH since
  # the machine's box will let anyone log into it. So instead we'll put the
  # machine on a private network.
  config.vm.hostname = "mailinabox.lan"
  config.vm.network "private_network", ip: "192.168.56.4"
  config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.network "forwarded_port", guest: 443, host: 8443


  config.vm.provision :shell, :inline => <<-SH
    # Set environment variables so that the setup script does
    # not ask any questions during provisioning. We'll let the
    # machine figure out its own public IP.
    export NONINTERACTIVE=1
    export PUBLIC_IP=auto
    export PUBLIC_IPV6=auto
    export PRIMARY_HOSTNAME=auto
    #export SKIP_NETWORK_CHECKS=1

    # Start the setup script.
    cd /vagrant
    setup/start.sh
SH
end

EDIT: Wow. Strange stuff happened. When I clicked on the link you provided for the private IP, I worked. But when i type it in my address bar, it does not work. Strange
:grinning:

If you want to use the hostname, you can add this line to your /etc/hosts file:

192.168.56.4 mailinabox.lan

@dms, JoshData

Thanks very much guys for all the help. I have the app setup and running locally as required. Now my next objective is modification of roundcube.

I even discovered that the login mechanism I want to implement is not necessarily a MiaB thing but a roundcube thing, so my next line of enquiries will be on their forum.

Thank you all very much. I am very grateful for the help and pointers.
God bless y’all.

Good day everyone.

Just wanted to fact check something.

Baser on roundcube docs, to use OAuth, the mail server needs to support XOAUTH for both IMAP and SMTP servers Roundcube connects to.

Does MiaB support XOAUTH?

Thanks.