Email Hosting Script: Setting Up Your Own Email Hosting Solution
26.05.2026
Choosing the Right Email Hosting Stack
There are several prebuilt scripts and tools that can be used to set up email hosting. Popular choices include:
For closely related self-hosted mail / Dovecot topics, see Understanding dovecot_virtual_delivery in Dovecot Mail Server, Understanding dovecot_virtual_delivery, and MX Hosting Complete Guide.
- Mail-in-a-Box: A script that sets up a complete email server.
- iRedMail: An open-source email server solution.
- Modoboa: A modular email hosting and management platform.
- Postfix + Dovecot: A manual configuration for flexibility.
Requirements for Hosting Email
Before setting up email hosting, ensure you have:
- A Domain Name: e.g.,
example.com. - A VPS or Dedicated Server: Email servers are resource-intensive, so shared hosting may not suffice.
- Operating System: Preferably Linux (Ubuntu, Debian, CentOS).
- DNS Management: Ability to update DNS records (MX, SPF, DKIM, DMARC).
Email Hosting Script Options
Mail-in-a-Box
- Overview: Automates the setup of an email server.
- Features:
- Handles email, webmail, DNS, and SSL automatically.
- Easy to install and maintain.
- Installation:
curl -s https://mailinabox.email/setup.sh | sudo bash - Requirements:
- A clean Ubuntu 18.04 or 20.04 server.
- Root access.
iRedMail
- Overview: A full-fledged email server solution.
- Features:
- Web-based management.
- Anti-spam and anti-virus tools.
- Installation:
- Download the installation script:
wget https://github.com/iredmail/iRedMail/archive/refs/tags/1.5.2.tar.gz tar -xvzf 1.5.2.tar.gz cd iRedMail-1.5.2 chmod +x iRedMail.sh ./iRedMail.sh - Follow the prompts to configure.
- Download the installation script:
Modoboa
- Overview: Modular email server with an admin panel.
- Features:
- Web-based email client.
- User and domain management.
- Installation:
wget https://raw.githubusercontent.com/modoboa/modoboa-installer/master/modoboa-installer.pypython3 modoboa-installer.py install --interactive
Manual Stack with Postfix and Dovecot
- Overview: Set up a custom email server using Postfix (SMTP server) and Dovecot (IMAP/POP3 server).
- Steps:
- Install Required Packages:
sudo apt-get install postfix dovecot-imapd dovecot-pop3d - Configure Postfix:
- Edit
/etc/postfix/main.cfto set:myhostname = mail.example.com mydomain = example.com myorigin = /etc/mailname mydestination = example.com, localhost
- Edit
- Configure Dovecot:
- Edit
/etc/dovecot/conf.d/10-mail.conf:mail_location = maildir:~/Maildir
- Edit
- Restart Services:
sudo systemctl restart postfix dovecot
- Install Required Packages:
Configuring DNS Records for Your Email Server
To ensure your email server works correctly, you must configure the following DNS records for your domain:
MX Record:
- Points to your mail server.
- Type: MX
- Host: @
- Value:
mail.example.com - Priority: 10
SPF Record:
- Authorizes your server to send emails.
- Type: TXT
- Host: @
- Value:
v=spf1 mx ~all
DKIM Record:
- Digitally signs your emails.
- Use the email hosting script to generate a DKIM key.
DMARC Record:
- Protects against spoofing and phishing.
- Type: TXT
- Host:
_dmarc - Value:
v=DMARC1; p=none; rua=mailto:dmarc@example.com
Accessing Your Email
Webmail:
- Many scripts include a webmail client like Roundcube or RainLoop.
Email Clients:
- Configure your email clients (e.g., Outlook, Thunderbird) using:
- Incoming Mail Server (IMAP/POP3):
- Server:
mail.example.com - Port: 993 (IMAP SSL), 995 (POP3 SSL)
- Server:
- Outgoing Mail Server (SMTP):
- Server:
mail.example.com - Port: 465 (SSL) or 587 (TLS)
- Server:
- Incoming Mail Server (IMAP/POP3):
Testing Your Email Setup
- Send Test Emails:
- Use your new email account to send test messages.
- Check Deliverability:
- Use tools like Mail Tester to ensure your email is not marked as spam.
- Monitor Logs:
- Check server logs for errors:
tail -f /var/log/mail.log
- Check server logs for errors:
Securing Your Email Server
- Enable SSL/TLS:
- Use Let's Encrypt to secure your email server with SSL.
sudo apt-get install certbotcertbot certonly --standalone -d mail.example.com
- Use Let's Encrypt to secure your email server with SSL.
- Anti-Spam Tools:
- Install tools like SpamAssassin or Rspamd.
- Firewall Configuration:
- Allow only necessary ports (25, 465, 587 for SMTP, 993/995 for IMAP/POP3).


