How to Host Your Own Email Server (with CyberPanel)

by

Hey there! Some links on this page may be affiliate links which means that, if you choose to make a purchase, I may earn a small commission at no extra cost to you. I greatly appreciate your support!

In this tutorial, you will learn the process of hosting your own email server. We will be using the open-source hosting control panel CyberPanel as our email server. The reason for this choice is because CyberPanel makes it extremely easy to generate all the necessary DNS mail records like DKIM, MX, and PTR. This is something that typically requires a great deal of knowledge in order to prevent your emails from being marked as spam.

By the end of this tutorial, you will have a full-functioning and properly configured email server. Let’s get started.

Note: In this tutorial, I am using a Linode VPS running Ubuntu 20.04 LTS as my server and NameCheap as my domain name registrar for site1.xyz. While you don’t have to use these services, the following examples will be specific to them, but the same concepts will apply wherever your hosting is and domain name resides.

1. Stand Up a Server

Wether you use a Linode VPS like I do, or have a physical server in your home, you will need a server to host your email. While I am running Ubuntu 20.04 LTS on my email server, CyberPanel also supports Ubuntu 18.04 at the time of this writing.

Minimum systems requirements for CyberPanel are as follows:

  • 1 GB or above RAM
  • 10GB or above disk space

Take note of the external IP address of your server. You will need that in the next step. The IP address I will be using in this example is 104.237.157.248.

2. Register Personal DNS Servers

What makes hosting an email server with CyberPanel so easy is the fact that CyberPanel manages all of your DNS mail records for you. In order for this to happen, we need to set up personal DNS servers with our registrar and then proceed to create a private nameserver.

To register personal DNS servers with NameCheap, access your domain name from your Domain List. Click on the Advanced DNS tab and add two standard nameservers of ns1 and ns2 with the IP address of your server.

Namecheap Personal DNS servers ns1 and ns2

You will end up with two nameservers, both of which are associated with the same IP address.

  • ns1.site1.xyz
  • ns2.site1.xyz

Next, go to the Domain tab for your domain name. Under the Nameservers section, select Custom DNS and add the two nameservers that you just created.

NameCheap custom DNS nameservers

3. Install CyberPanel on Your Server

Log in to your server via SSH and install CyberPanel with the official installer script.

sh <(curl https://cyberpanel.net/install.sh || wget -O - https://cyberpanel.net/install.sh)

During the installation, choose option 1 to install CyberPanel with OpenLiteSpeed and make sure you install Postfix which will act as our mail server. All other options in the installation are up to you.

CyberPanel command line installation

Here are the options I chose.

  • 1 – Install CyberPanel
  • 1 – Install CyberPanel with OpenLiteSpeed
  • Y – Full installation
  • N – Remote MySQL
  • Enter – Press Enter key to continue with latest version
  • s – Specify the admin password
  • n – Do you wish to install Memcached extension and backend?
  • n – Do you wish to install Redis extension and backend?
  • Y – Would you like to set up a WatchDog?

4. Email Server Setup

Now that CyberPanel is installed, we can set up the email server.

The CyberPanel hosting control panel runs on port 8090 by default. To access the dashboard, navigate to your IP address followed :8090. For example, since my IP address is 104.237.157.248, I will go to http://104.237.157.248:8090 in a web browser.

At the login screen, enter admin for the username and the password that you created during installation.

CyberPanel hosting control panel login screen at port 8090

Within the hosting control panel, there are three steps we need to take in order to set up our self-hosted mail server.

A. Create a Website Container

The easiest way to associate your domain name with CyberPanel is to create a website. Although it’s possible, you won’t be hosting any content on the website right now. From the perspective of CyberPanel, this website is more like a container for a website.

To create the website container, go to Websites -> Create Website.

Fill out the form with your domain name and make sure you check the DKIM Support box.

Create website with CyberPanel with DKIM support for an email server

B. Create Nameservers

Remember how you registered personal DNS servers at the beginning of this tutorial? Now you must create these nameservers in CyberPanel.

To create nameservers in CyberPanel, navigate to DNS -> Create Nameserver.

Fill out the form with your nameservers from earlier and the IP address of your server.

Create nameservers in CyberPanel

 

C. Issue an SSL Certificate

In order to make our mail server secure and encrypted, you must install an SSL certificate. You can do this in one click with a free SSL certificate from Let’s Encrypt.

Go to SSL -> Mailserver SSL.

Select your domain name from the dropdown list and click on the Issue SSL button.

Issue an SSL certificate for Postfix mailserver in CyberPanel

At this point, it’s a good idea to check the status of your DNS settings. You can use a free website like UltraTools to look up your DNS settings. It may take some time for these changes to propagate across the internet (a few minutes to a couple days), so be patient before moving on to the next step.

5. Set Up Reverse DNS

In order for your mail server to work properly as far as DNS is concerned, it is extremely important to properly configure reverse DNS. Reverse DNS is exactly what you’d expect. Rather than associating a domain name with an IP address like is done with DNS, reverse DNS associates a domain name with an IP address.

To set up reverse DNS in Linode, click on the Networking tab. Under the IPv4 section, click the three dots associated with your IP address and click on Edit RDNS.

Edit reverse DNS for an IP address in Linode

In the resulting popup window, type in your domain name to associate your domain name with your IP address. In my case, I typed in site1.xyz.

Linode edit RDNS settings

It may take some time for your changes to propagate across the internet (a few minutes to a couple days). You can check the RDNS status with MXToolBox.

6. Create an Email Address

Now the exciting part you’ve been waiting for! Create an email address in CyberPanel by going to Email -> Create Email.

Fill out the form, specifying your domain name, and choose an email address and password. In my case, I picked tony@site1.xyz for my email address.

Create an email address in CyberPanel

7. Send and Receive a Test Email

You can access your email inbox by navigating to Email -> Access Webmail. The default email client is RainLoop.

Log in with the email credentials you just created to reveal your inbox.

RainLoop email login screen

Compose an email, and send it to a recipient of your choice. Within a few seconds, you will see your email pop up in the recipient’s inbox.

Respond to this email to test out the ability to receive emails.

Composing a message in RainLoop

As one final test, you can check to see if your email server is configured properly from the perspective of spam filters. To see if your mail server is configured properly as far as DNS mail records are concerned, you can use a free tool like Mail Tester. Simply send an email to the address, and within a few seconds, you will be given a spamyness score out of 10.

Use mail-tester to check spam email score

A full video tutorial of hosting your own email server is available below. Please let me know in the comments of the video or in the comments section below if you have any questions. I’ll do my best to help you out.


Meet Tony

With a strong software engineering background, Tony is determined to help as many people as possible start their online busines. Discover why Tony quit his hedge fund job to pursue this mission. You can send Tony a message here.

6 thoughts on “How to Host Your Own Email Server (with CyberPanel)”

  1. Hey Tony,
    I am loving the tutorial, I ended up using the Digital Ocean version and I use Cloudflare for a DNS (using the cyberpanel cloudflare sync).

    I cant get my mail server to work correctly, I have a site created and a mailserver. It looks to me like everything regaurding DKIM and other records are in the cloudflare DNS.

    When I go to login to the rainloop it says account cannot access and if I try to connect it to an external client it says it can not connect either.

    Do you know of any resources or perhaps can you point me in the right direction? Thanks!

    Reply

Leave a Comment