Building your own email server can seem difficult, but it’s a rewarding project. By using Virtualmin on an UltaHost VPS, I found a way to take control of my email communication. This guide will walk you through the steps to build an email server using Virtualmin and UltaHost VPS, making it easier to manage and secure your email.
Let’s get started and explore how to build your email server effectively and securely.
Prerequisites
With the right tools and a bit of time, creating an email server is achievable for anyone. I’ll share the exact steps I took, covering everything from installation to security measures.
- An UltaHost VPS or any VPS with root access and open port 25
- A domain name (I recommend using Namecheap for ease of setup)
- An SSH client (like Bitvise or PuTTY)
- Basic knowledge of Linux commands
How to Build an Email Server Using Virtualmin and UltaHost VPS
Step 1: Setup UltaHost VPS
To begin setting up our UltaHost VPS, we first need to select the right plan.
Next, we will sign up for our selected plan.
- Choose a VPS Plan: Go to the UltaHost website. Select the desired plan that fits our email server requirements.
- Select Location: Choose a data center location that is closest to our target audience for better performance.
- Create an Account: Fill out the necessary details.
Step 2: Connect to Your Server via SSH
After completing our purchase, we will receive an email with our VPS details.
Now we can log into our VPS using SSH.
- Use a Terminal: On Windows, we can use an SSH client like PuTTY. On macOS or Linux, we can use the terminal.
- Connect: Enter the command ssh root@your_vps_ip and input the password provided in our email.
Or use Bitvise to connect to your server easily.
For advanced users, if you’re using Windows, you can follow my guide on generating SSH keys on Windows using Bitvise and PuTTY.
Once we are logged in, we are ready to configure our server. We can install the necessary packages and prepare our environment for Virtualmin. We’ll cover this later on.
Step 3: Setup DNS Records
A domain name is crucial for my email server. You must register a domain through a domain registrar like Namecheap. Once you have a domain, you need to configure DNS settings to connect the domain to my email server.
Key DNS Records:
- MX Records: These direct email traffic to my server.
- A Records: This points my domain to the VPS IP address.
- SPF Records: These help prevent spammers from sending emails on my behalf.
You can follow this guide. Be sure to change the domain with your own domain.
Record Type | Name | Content | Priority | TTL |
A | webshanks.shop | YourServerIP | Auto | |
A | YourServerIP | Auto | ||
MX | webshanks.shop | mail.webshanks.shop | 10 | Auto |
TXT | _dmarc | v=DMARC1; p=none; | Auto | |
TXT | webshanks.shop | v=spf1 a mx ip4:181.214.152.68 ~all | Auto |
After setting up these records, it may take some time for changes to propagate. It’s important to check the DNS status to ensure everything is configured correctly for my email to function.
Step 4: Setup Mail Hostname and rDNS
It’s essential to configure your mail server’s hostname and reverse DNS correctly.
For easier configuration, contact UltaHost support and request to change your hostname along with rDNS to open port 25.
With this, every time you reinstall your OS, you don’t need to change your hostname on the CLI.
Step 5: Install Virtualmin
I have created a separate tutorial for installing Virtualmin. Be sure to check that out. But I’ll put the commands here.
Before installing Virtualmin, ensure your system is updated:
sudo apt update && sudo apt upgrade -y
Then install Virtualmin.
sudo sh -c "$(curl -fsSL https://software.virtualmin.com/gpl/scripts/virtualmin-install.sh)" -- --bundle LAMP
Step 6: Install Roundcube
Once your Virtualmin is configured properly, it’s time to install Roundcube as our webmail.
Roundcube is a user-friendly webmail client that you’ll install on your server.
On your Virtualmin dashboard, go to Manage Web Apps on the left menu.
Then choose and install Roundcube.
Step 7: Create an Email User
Next, you’ll need to create an email user. In Virtualmin, go to Virtualmin > Edit Users and click Add mail user. Fill in the user details.
Step 8: Add DKIM keys
We have only one piece remaining to configure our email server: the DKIM fully.
To find your DKIM on Virtualmin, go to DNS Settings > DNS DKIM Record.
Remove the quotation marks on a notepad.
Then add the records to your DNS provider.
Record Type | Name | Content | TTL |
TXT | 202408._domainkey | Your DKIM record | Auto |
This will be your final DNS map.
Step 9: Test Your Email Server
It’s time to test your email server! Open Roundcube and send a test email to ensure everything is working as expected.
Go to mail.yourdomain.com/roundcube and login using the user you created a while ago.
Then send a test email to the Mail-tester.
We got a 10/10 score!
Let’s try to send a test email to Gmail.
We’ll use the same email.
We received it directly in our inbox.
Our reply: Thank you! I will be attending.
Step 10: Configure Email Clients
Finally, configure your email clients (e.g., Outlook, Thunderbird, or mobile devices) to access your new email server. You’ll need the following settings:
- IMAP/POP3 Server: mail.yourdomain.com
- SMTP Server: mail.yourdomain.com
- Username: Your full email address
- Password: The password you created for the email account
These settings are found on Edit Users > Show Email Client Settings.
Troubleshooting
If you encounter issues, here are some common problems and solutions:
- Emails not sending/receiving: Check your firewall settings and ensure ports 25, 465, 587, 993, and 995 are open.
- SSL certificate errors: Make sure you’ve properly set up SSL certificates in Virtualmin.
- Emails marked as spam: Ensure you’ve correctly set up SPF and DKIM records.
FAQs
Is it safe to run my own email server?
Running your own email server can be safe if properly configured and maintained. However, ongoing attention is required to security updates and best practices.
Can I host multiple domains on one Virtualmin email server?
Yes, Virtualmin supports hosting multiple domains on a single server. You might find my guide on hosting multiple websites on one server helpful, as the concept is similar to email hosting.
How do I backup my email server?
A: Virtualmin includes backup features. You can schedule regular backups of your entire server or just your email data by navigating to Webmin > Backup Configuration Files and choosing how you backup your files.
Conclusion
Building your own email server using Virtualmin gives you control over your emails and eliminates dependency on external providers.
Follow these steps to set up a fully functional mail server, and don’t forget to configure your DNS records and email clients correctly.
If you’re looking for more VPS and email server setup tutorials, check out some of my other guides, such as setting up a free email server with RackNerd VPS or setting up Mailcow in CloudPanel.