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 #1: 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.

Note #2: If you do choose to use Linode, email ports are disabled by default. Please follow the instructions here to enable email ports on your Linode server.

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.

If you are not using Linode, you will need to define a DNS record of type PTR while also maps your IP address with your domain name.

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.

YouTube video


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.

32 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
  2. Hi Tony,

    Sent you a question on Youtube on a few issues I like to know before getting started. After I configure this smtp server up for email – can I use a mail client to send emails – like outlook, profitmailrr (which is like an autoresponder using their option to add my own smtp server) or software like “Super Email Sender”? Next, is there a tool that can verify spam prevention when it sends the email to a prospect – in other words with this server sending emails out to not go directing into their spam box? Or, would that be covered with what you did above in this video with the practice of sending emails out slowly per day, like 25 the first day, then 50 next, and 75 the following, etc? Would that solve that issue to warm up the server to other servers when receiving emails us this new smtp server. [Hope that question makes sense?]

    Reply
    • Hi David. I haven’t personally connected this setup to an external mail client, but I would think its possible to do. Unfortunately I’m not familiar with any spam prevention tools or best practices.

      Reply
    • Typically PTR records need to be defined by the owner of the IP address. In your case, this would be your internet service provider.

      Reply
  3. thanks Tony. A couple of notes … Linode blocks all email ports by default so just before the step to test email you will need to lodge a support call with linode to open ports. It would help us noobs to mention that creating the DNS records that they are “A” type. The setting of IPV4 reverse proxy has changed slighly with Linode so you might want to update the location details of RDNS. Cheers

    Reply
    • DKIM keys will be created when you select the “DKIM Support” checkbox in step 4a. However, as you point out Mike, you can also do this manually.

      Reply
  4. PS : Please delete this….

    You comment system errors on “post Comment” saying failed capture (which it didnt offer) and then when you “Post Comment” a second time it works! FYI

    Reply
  5. Hi Tony,

    Very nice tutorial.
    Please whats the sending limit fo this webmail?
    Can it work as an smtp cos i tried to use it on gamadyne, the port 587 is not connecting but the 465 is connectiing…

    Hope to read from you sir

    Reply
  6. Hi Tony, this tutorial is gold. Keep it up! However, after following through to the test section, I sent to two separate Gmail accounts and did not see the test messages. Anything wrong? Thanks for the tutorial

    Reply
  7. Excellent article, and well presented. But here, one of your mentioned tools for checking DNS records (ultratools DNS records checking link) is somehow not functional anymore. Here is another tool I would like to recommend from an authoritative website. That tool gives you the DNS records lookup of the top most used 12 DNS records. The link to that tool is
    https://dnschecker.org/all-dns-records-of-domain.php
    You can add that tool as a replacement to ultratools DNS Lookup.

    Reply
  8. Hi Tony

    I tried the tutorial with Digital ocean vps and Contabo vps.
    Configuration was smooth an easy.
    But when I try to send a test email it aways say, CAN’T SEND MESSAGE

    What might be the issue and how to fix it ?

    Cordially

    Reply
  9. Hello! Thanks for your blog post.
    I have a question, how can i change the default url to rainloop? I have a customer and they dont like the default url with the port.

    Reply
  10. if I’ve to set up emails for 2/ multiple domains, then Can I set those in the same cyber panel, by making 2 or multiple sites?

    Also, how can I change the location of mails saved on the server?
    can I attach additional disk volumes whenever needed?

    Reply
  11. Hy Tony,
    Thanks for such nice tutorial. But i am unable to send emails from different website i.e in your example you had set up reverse dns for site1.xyz, and what if we have to send email from different(site2.xyz) website hosted in same vps. What might be the configuration for info@site2.xyz so that it can send email to gmail accounts; In my case i can send emails to other email providers but the google rejects the email, although spamming rating is 10/10.

    Reply
  12. hey toni,
    i brought linode and namecheap to setup email server as you.when i install cyberpanel it says error to port 25 and the emails i send through rain loop didnt received..how do i open port 25

    Reply
  13. Hi Tony. Everything works nice but when I add new dns records in the cyberpanel dns manager, they are not propagated. Even after 3 days.

    What can I do?

    Reply
  14. I wanted something similar… I wanted a subdomain to point to another Zimbra mail server, because it’s working and I don’t want to use Rainloop…

    Reply

Leave a Comment