Hosting your own mail server on the cheap

Hosting your own mail server is finally easy! Here I hope to provide an in-depth guide showing you how to set up your own server which won’t get you or your clients blacklisted!

Buying a domain

You’re going to want a cool email address like [email protected] – so head over to Namecheap and purchase a domain for as little as $1 for a .xyz

Get yourself a server!

Ramnode is one of my favourite server hosts due to the amazing support, sometimes they’ve replied to my requests instantly, and they’re always very fast to deliver servers, I assume you want to do this now so head on over to Ramnode and get a server for as little as $15 a year, not bad seeing as you’ve got email for a year for $16 and unlimited users, eh?

Screen Shot 2015-08-17 at 02.52.43

Install Your Server and VestaPanel

Now you’ll want to configure your server – if you have purchased a server with under 4096MB of RAM, you’ll want to install a 32 bit version of Debian, use Debian because it plays nicely with Vesta.

Once you have your VPS up and running, login via ssh with root password Ramnode gave you.

Seeing that we have a new VPS running, go ahead and refresh the package indexes:

apt-get update

Now may also be a good time to upgrade any packages that might need it:

apt-get dist-upgrade

Install Vesta

Next, we download the Vesta installation script:

curl -O http://vestacp.com/pub/vst-install.sh

After which we run this script:

bash vst-install.sh

The install script shows us some information on the software that will be installed:

1

 

 

 

 

 

 

 

 

 

 

Press “y” and “enter” to proceed with the installation.

Then enter a valid email address you have access to

Upon completion, you will be presented with the following information:

2

 

 

 

 

 

 

 

 

 

Take note of the address, username, and password. You will need these to log in to the control panel.

Log in to Vesta

Now that Vesta is installed, open your browser and go to the address that Vesta gave you in step two. If you didn’t take note of it, the address will be as follows:

https://<your-server-IP-address-or-URL>:8083

*Make sure to use HTTPS, you will be presented with a prompt to confirm visiting your site without a valid SSL certificate, click Continue in Safari or Advanced > Proceed in Chrome

Screen Shot 2015-08-17 at 03.04.24

Set Up Your DNS

Head back over to Namecheap and log in to your DNS management panel, then select ‘All Host Records’

Screen Shot 2015-08-17 at 03.08.53

 

 

 

 

Add an A record pointing to your new server with the hostname ‘mail’ where the IP address is that of your new Ramnode VPS.

Screen Shot 2015-08-17 at 03.11.45

 

Then ensure that your Mail settings are like so:

Screen Shot 2015-08-17 at 03.11.52

 

And save your changes, you will then see the following section:

Screen Shot 2015-08-17 at 03.14.31

Configure the mail server hostname to the one you just set up i.e ‘mail.yourdomain.com’ three times with the three different MX preferences – this ensures all providers’ emails will reach you!

Set up your email account

Log back into your VestaCP instance and select mail, then add a new domain (drop the mail. part – or the subdomain) and make sure to select DKIM support. Then add an account. You can then either open webmail and receive emails or set up your mail client using mail.yourdomain.com as the IMAP and SMTP server and [email protected] + password as the username/password.

Screen Shot 2015-08-17 at 03.25.20

Congratulations! You can receive mail!

But! you can’t send mail without being classed as spam just yet. Now you need to set your reverse hostname in your ramnode VPS control panel with Ramnode’s solusVM CP. Scroll to the bottom of your server and select the ‘Hostname’ tab like so and enter the previously configured mail server hostname.

Screen Shot 2015-08-17 at 03.19.17

DKIM and SPF setup on your domain

Now comes the last part – we set up DKIM (DomainKeys Identified Mail) and SPF (Sender Policy Framework) so that hosts like Google Mail, Apple, and other providers don’t class our emails as spam.

Log into vestacp’s webmail with http://mail.yourdomain.com/webmail using [email protected] and your password and send a blank email to the following address:

[email protected]

You will then receive results from [email protected] – search for the term ‘dkim-signature’ and you should see a long string like the following:

dkim-signature:v=1;'20'a=rsa-sha256;'20'q=dns/txt;'20'c=relaxed/relaxed;'20'd=yourdomain.com;'20's=mail;'20'h=Mime-Version:To:Date:Message-Id:Subject:Content-Transfer-Encoding:Content-Type:From;'20'bh=47DEQpj8HBSa+/TImW+sJCeuQeRkm5NMpJWZG3hSuFU=;'20'b=;

Strip out the ‘dkim-signature:’ section, and create a TXT record in the Namecheap ‘All Host Records’ section with ‘_domainkey’ as the host and the text you created earlier without ‘dkim-signature:’ as the string.

Create a second TXT record with ‘yourdomain.com’ as the hostname and the following string as the text entry but substitute the IP address for your own server:

v=spf1 a mx ip4:1.2.3.4 ~all

There you go!

You can now send and receive emails :-)

5 thoughts on “Hosting your own mail server on the cheap

  1. Aivaras says:

    Had previously tested Vestacp I really appreciate how simplistic yet sophisticated the control panel is.
    I actually have had a 128ram ramnode vps for quite some time and thought there was no way Vestacp would run on such a small ram footprint. Your guide showed me wrong and I really thank you for this. Just now I installed it on my 128mb ram node and there’s still plenty of ram left. Wow, I have to say. Waiting for dns records to propogate, hopefully will be able to send mail to gmail, for now it doesn’t work.

    • mmaton says:

      Glad I could help! If you have any questions or issues, hit me up on IRC, i’m on #ramnode at irc.netchat.io:6667 as mmaton :)

  2. Aivaras says:

    For some reason my Vestacp was not signing emails with DKIM properly, following this guide fixed it : https://www.port25.com/support/domainkeysdkim-wizard/

  3. John says:

    Hey! Do you maybe know what’s the difference between [Premium] OpenVZ SSD and [Massive] OpenVZ SSD-Cached plans? How much free RAM do you have averagely? Thank you for the answers in advance! :)

  4. Aivaras says:

    Take the 80gb openvz yearly plan, you can use it for backups too!
    Current ram usage is 26MB used, 101 free and 63 ram swap used, 0 free. I have turned off ftpd(use winscp), named, fail2ban so it runs smoothly.

Leave a Reply

Your email address will not be published. Required fields are marked *