Cloudflare Email Routing with Gmail

Having your own domain is great. Having an email address that uses your domain, is even better.

Published: 2024-08-04


Table of Contents


Why?

When I bought this domain, I did so with the intention of publishing a site to showcase some of my work, as well as to make notes on things I have done, so that they are easily accessible. I had the thought cross my mind that, while publishing work is good, it would be even better if there was a single point of contact that could be used if there were questions, or areas of improvement.

The most obvious method of communication, and the one I went with was Email. However, I was not going to publish my personal email so that it could be subject to spam, after being found by bots and crawlers on the internet. With this in mind, I set to work, finding ways to create an email address for this domain. Luckily, Cloudflare, who I purchased this domain from, offers an email routing service that is free.

Cloudflare Email Setup

You need to create the email address you want to use with your domain. Log in to your Cloudflare dashboard, and select the relevant website/domain.

Go to Email → Email Routing. Enable it, if it isn't already, and follow the on-screen prompts, which should guide you through the adding of the necessary DNS entries to your domain.

Go to Routing rules, and create a new address. This should be [email protected], where foo is the address portion you wish to create. In destination addresses, enter your full Gmail address, for example [email protected]. Save your changes.

Cloudflare will send a verification email to your destination (Gmail) address. You need to acknowledge this, in order to allow emails to be automatically forwarded to this email address.

Finally, you will be prompted to add DNS records to your domain. Confirm this, and Cloudflare will add the records to your DNS management for you.

You will now be able to recieve emails that are sent to your domain email address! Now we need to allow sending responses from that email address as well.

Google Account Setup

Your target Google account should have 2-Factor Authentication (2FA) enabled. If this is not already enabled, you should enable this from within your Google account settings.

Once 2FA is enabled, you will need to generate an App Password to enable the sending of mail from your domain email address. Give it a memorable name, and keep a copy of it somewhere safe, such as in a password vault. If you ever revoke this password, you will no longer be able to send emails from your domain address. Recieving of emails will be unaffected.

Gmail Configuration

Login to Gmail from a web browser, go to Settings → See All Settings → Accounts and Import → Send Mail As, and select "Add another email address". In the window that appears, set the email address to the domain address created in Cloudflare, for example: [email protected]. Make sure that "Treat as an alias" is enabled, before continuing.

In the next form that appears, set the following details:

Select "Add account", and you should now be able to send emails from both your Gmail address and your domain address. This new address will also be available on Gmail apps for Android (and presumably iOS too).

Sources