Setting Up a Mail Server from Cloudflare to Hosting

Setting Up a Mail Server from Cloudflare to Hosting

Using Cloudflare to point your domain to hosting, but confused about how to set up the mail server or MX records? In this article, we will discuss how to set up a mail server from Cloudflare to hosting, especially cPanel and including SPF and DKIM configuration.

Since we are only discussing how to set up the mail server here, make sure your domain is already connected to Cloudflare and you have active hosting, whether it is web hosting or email hosting.

Setting Up a Mail Server from Cloudflare to Hosting

In this guide, we will use the following configuration:

  • Main domain: partof.my.id
  • Email subdomain (for MX setup): mail.partof.my.id
  • Server IP: 192.168.1.1
  • Hosting: cPanel

Please feel free to adjust the configuration you will use according to your domain name, IP, and hosting control panel.

1. Get the Server IP Address

The first step you need to take to connect a mail server from Cloudflare to hosting is to get the IP address of the server you are using.

Usually, the server IP address is sent to your email when you purchase hosting services. But if you did not save that email and forgot the server IP address, you can log in to your hosting control panel, such as cPanel, then in the General Information section, you will find the server IP address information.

Setting Mail Server Dari Cloudflare ke Hosting - 1

2. Create a Subdomain in Cloudflare

After getting the server IP address, you can then create a subdomain in Cloudflare by opening the DNS → Records menu for the domain you are managing.

Setting Mail Server Dari Cloudflare ke Hosting - 2-1

Once you are on the DNS Record page, click the Add record button to add a new subdomain, and make sure the record type is A.

Setting Mail Server Dari Cloudflare ke Hosting - 2-2

In the Namecolumn, enter the name of the subdomain you want to create, for example Mail. Then in the IPv4 address column, enter your server IP address, for example 192.168.1.1, and the most important part that is usually skipped and not written in most articles, You must turn off the Proxy status! so the result will look like this

Setting Mail Server Dari Cloudflare ke Hosting - 2-3

If everything is filled in, you can save the changes and continue to the next step.

3. Add an MX Record

So that your domain can point to the server, you need to create one or more MX Records (if using web or email hosting, you usually only need one).

Just like in the second step, you can add a new record, but change the record type from A to MX

Setting Mail Server Dari Cloudflare ke Hosting - 3-1

In the Namecolumn, enter your domain name, for example partof.my.id, or you can also use at (@). Then in the Mail servercolumn, you can fill it with the subdomain you just created, for example mail.partof.my.id.

Finally, you need to enter a Priority from 0 to 65535. The smaller the priority number, the higher the priority of that MX record, and it will be read first.

Setting Mail Server Dari Cloudflare ke Hosting - 3-2

Saved? Let's move on to the next step.

4. Get SPF and DKIM Records

Although pointing your domain to the mail server already allows you to send emails, if you send to a large email provider, such as Gmail, you will get an error message that looks something like this

Setting Mail Server Dari Cloudflare ke Hosting - 4-0

The solution is that you need to add SPF and DKIM records to Cloudflare.

But where can we get both of those records?

To get both records, first you need to open the Email Deliverability page from your cPanel hosting

Setting Mail Server Dari Cloudflare ke Hosting - 4-1

After being on the Email Deliverabilitypage, click the Manage button on the domain you are using

Setting Mail Server Dari Cloudflare ke Hosting - 4-2

Now you can get the records for SPF and DKIM from that page. Just copy both records to add them to Cloudflare.

Setting Mail Server Dari Cloudflare ke Hosting - 4-3

Setting Mail Server Dari Cloudflare ke Hosting - 4-4

5. Add SPF and DKIM

Return to Cloudflare and add DNS again. Now you need to add two DNS records with the TXT record type.

First, let's add SPF. For SPF, you usually only need to fill in the Name column with your domain name, or you can also just write at (@). Then in the Content column, you can fill it with the SPF you copied from cPanel, or you can copy the following code

v=spf1 +mx +a +ip4:192.168.1.1 ~all

Make sure to change 192.168.1.1 with your server IP address!

Setting Mail Server Dari Cloudflare ke Hosting - 5-1

If it has been added, you can add another record with the same type, which is TXT.

In the Namesection, enter default._domainkey as stated in your hosting, then in the Content section, enter the DKIM record that is in your hosting. (starting with v=DKIM1; k=rsa; p=…)

Setting Mail Server Dari Cloudflare ke Hosting - 5-2

Now you have finished the configuration and can try sending an email to Gmail again.

6. Try Sending an Email

The last step you need to take to connect the mail server from Cloudflare to hosting is to try sending an email.

To try sending an email, you can open the Email Accounts page in your cPanel, then select the email account you will use to send the email.

If successful, you will not get an error message again, and the email will successfully reach its destination.

Setting Mail Server Dari Cloudflare ke Hosting - 6-1

If you still cannot send emails to Gmail normally, you just need to wait a few hours. But if after 24 hours it is still the same, then you need to re-check the SPF and DKIM you added.

Written by

Muhammad Khoirun Nasikin

I enjoy tinkering with WordPress, hosting, VPS, web development, and various small experiments related to websites. I have over 3 years of experience in the web hosting industry.

COMMENTS

Loading...