Era Host hosting
EraHost – Free Domain, Cheap Hosting!
Client Area
Support 24/7
Menu

Email Hosting Script: Setting Up Your Own Email Hosting Solution

4 min read
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:

Email Hosting Script Self-Hosted
Self-hosted email — possible, not actually cheaper than Workspace.

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:

  1. A Domain Name: e.g., example.com.
  2. A VPS or Dedicated Server: Email servers are resource-intensive, so shared hosting may not suffice.
  3. Operating System: Preferably Linux (Ubuntu, Debian, CentOS).
  4. 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:
    1. 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
    2. Follow the prompts to configure.

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.py
    python3 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:
    1. Install Required Packages:
      sudo apt-get install postfix dovecot-imapd dovecot-pop3d
    2. Configure Postfix:
      • Edit /etc/postfix/main.cf to set:
        myhostname = mail.example.com
        mydomain = example.com
        myorigin = /etc/mailname
        mydestination = example.com, localhost
    3. Configure Dovecot:
      • Edit /etc/dovecot/conf.d/10-mail.conf:
        mail_location = maildir:~/Maildir
    4. Restart Services:
      sudo systemctl restart postfix dovecot
Linux VDS
High performance for your projects
  • Root access and flexible setup
  • Control panel
  • NVMe disks
  • DDR5
Linux VDS

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)
    • Outgoing Mail Server (SMTP):
      • Server: mail.example.com
      • Port: 465 (SSL) or 587 (TLS)

Testing Your Email Setup

  1. Send Test Emails:
    • Use your new email account to send test messages.
  2. Check Deliverability:
    • Use tools like Mail Tester to ensure your email is not marked as spam.
  3. Monitor Logs:
    • Check server logs for errors:
      tail -f /var/log/mail.log

Securing Your Email Server

  1. Enable SSL/TLS:
    • Use Let's Encrypt to secure your email server with SSL.
      sudo apt-get install certbot
      certbot certonly --standalone -d mail.example.com
  2. Anti-Spam Tools:
    • Install tools like SpamAssassin or Rspamd.
  3. Firewall Configuration:
    • Allow only necessary ports (25, 465, 587 for SMTP, 993/995 for IMAP/POP3).
Frequently asked questions
Mail-in-a-Box: simplest install, single-server, lightweight — good for 10-100 mailboxes. Mailcow: Docker-based, modern UI, easier to add features like ActiveSync — good for 100-1000+ mailboxes. iRedMail: most feature-rich (admin panel, multiple domains, integration with LDAP), but heavier. Pick by team scale and operational comfort.
Google Workspace ~$6/user/month. Self-hosted: $10-30/month VPS hosting 5-50 users — looks cheaper on paper. Reality: 4-10 hours/month of admin time (security patches, log review, queue management, blacklist incidents) at any reasonable rate costs more than the Workspace savings. Self-host for technical control, learning, or compliance — not for cost savings.
Missing or wrong PTR (reverse DNS). Many VPS providers don't set PTR by default; without it, Gmail/Outlook reject outbound. Request PTR from your VPS provider before sending production mail. Second most common: shared IP from a budget VPS provider on Spamhaus PBL (residential range block) — switch provider or use a relay.
Mailboxes are dataset that grows fast and can't be lost. Daily encrypted backups to off-site (Backblaze B2, AWS S3, separate VPS), retention 30+ days. Test restore at least quarterly. Mailcow has built-in backup scripts; Mail-in-a-Box ships backup tooling; iRedMail leaves backup to you. Backup is the difference between self-hosting and gambling.
Related articles
How to Link a Domain with Yahoo Mail and Use It as a Corporate Email
SMTP Hosting: Setup and Usage Guide
BD Hosting for VPS: Setup and Use