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 server 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
Whether you use a Linode server 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.
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.
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.
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.
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.
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.
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.
At this point, it’s a good idea to check the status of your DNS settings. You can use a free website like NsLookup.io 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.
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.
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.
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.
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.
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.
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.
47 Responses
When you get to 5. Set Up Reverse DNS. You show linode do you have to use that?
You should be able to add a PTR record to the DNS settings of your domain name as an alternative.
Hello Tony,
I have been running Cyber Panel like 12 time but everytime i have install this it give me a 503 error is there any way to fix this?
Sincerely,
Ben
This may seem basic but I am using a mac how do I Log in to my server via SSH
I have just the tutorial video for you https://youtu.be/SfTSBbaFN8Y
i can’t find where to add PTR record
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!
Hey! Would it be possible to provide specific error messages that rainloop is giving you?
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?]
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.
how can i set a PTR record with cyberpanel. I’m using my own pc to setup a mail server.
Typically PTR records need to be defined by the owner of the IP address. In your case, this would be your internet service provider.
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
Hi Mike, thanks for pointing that out. I mentioned this in the description of the video on YouTube but failed to mention here. I will update accordingly, and for anyone reading this, here’s the Linode documentation about enabling emails ports.
DKIM does not create keys by default. You need to go into DKIM manager and generate them manually. In my case it errored saying that I did not have permissions to the json file. I fixed this by running a cyberpanel upgrade using sh <(curl https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh || wget -O – https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh)
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.
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
Hi Mike. I am not seeing this behavior on my end. What browser are you using?
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
There is no sending limit. This can work as an SMTP server with port 465.
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
Hi Waheed
Did you find the solution ?
Im facing the same issue
Hey, I was wondering how I can get the IMAP and SMTP information to use this with an email client.
This is accessible at https://example.com:8090/rainloop/?admin and you can find the password for the admin user at /usr/local/CyberCP/public/rainloop.php. Once authenticated, go to Domains > example.com and you’ll be able to configure these settings.
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.
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
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.
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?
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.
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
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?
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…
Hi tony.
Can we set an email space quota in each account?
TIA
Hey,
I followed the exact same instruction. Still my mails are getting delivered in spam. Any idea how to debug or fix?
What does mail-tester.com suggest?
Hey,
I followed the exact same instruction using vultr.
but every time I try to sign to rainloop i get authentication error Any idea how to debug or fix?
Sorry, I’m not sure how to fix this
Hi tony,
I changed vultr to linode and I’m facing a problem with opening email ports with them.
i followed the step but they send me this message
——
“We’ve reviewed your account and we are unable to lift the SMTP restrictions from your Linode(s) at this time.
If you would like to request this again in the future, we ask that you wait until you have at least 3 months of positive billing history on this account.”
—–
can you please explain how you did that?
thanks
hi, tony. My DNS on Cyberpanel doesn’t work even though i followed the steps on this tutorial.
Master, congratulations on the tutorial. Even I, who am Brazilian, managed to understand and make it work… but my question is different… I want to use a server outside CyberPanel, for example, Zimbra… I have already created the server and it is working but how do I put it on CyberPanel? It has unique public domain and IP… How would I do this?
Hi, your tutorial is great but there is one problem. After I set RDNS and created email account, I can’t log in into webmail. It’s always authentication failed. Where did I wrong? Thanks!
Tony,
Thanks so much for the video. I am fairly experienced with Linux and I use Linode so this was perfect. Oddly I cannot send email but I can receive. the only address from which I can receive is the cyber panel address. Do you have any thoughts? Thanks,Andrew
Please see Note #2 at the beginning of this post
Most likely port 25 is blocked by your hosting provider. Contact your server provider and request to have port 25 opened.
Thanks so much for this guide it really helped!
Thank you tony very useful but i have problem i can receive mail but i cant send?
Thank you for this tutorial. Your instructions are clear and concise and i did not have any problems with setting up my own email account. Thanks again