Understand the concepts needed to send emails with a custom domain

My question today has to do with me not knowing the names/concepts of the things I probably need to fiddle with in order to achieve my desired result:

To be able to use [email protected], [email protected], ..., email addresses, where example.com is a domain name I own, ideally from a familiar interface like that of gmail.

I have a domain name in a registrar, and I am using the DNS records (not even sure which ones D:) to redirect requests to example.com to the IP of my virtual machine that I am renting, and where I have my website. What I want is to be able to send and receive emails that end with @example.com, but I don't even know what to Google for, because I don't know the terms of the things that might be involved.

I found things mentioning email hosting provided by the registrars, but I am not interested in paying extra money to get that working. I also found things talking about an MX DNS record, but that felt like it will only allow me redirect emails going to [email protected] to some other email address, say a @gmail.com email address I have.

In short, what are the concepts I should understand, and how would I go about doing this?


Solution 1:

You are on the right track. MX DNS records tell clients where to look for your mail host. So, if you have DNS "A" records pointing at one place for web hosting, you can have "MX" records pointing somewhere else for mail. When a mail client (or Message Transfer Agent, "MTA") tries to send an email to [email protected], it does a DNS lookup for the MX record of example.com, and then attempts to send the email to whatever address is returned. It gets more complicated than that, but that's the basics.

Several big email hosts allow you to set this up, but you might not be able to do it for free. Google "custom domain gmail" or something similar to find your preferred host.

Solution 2:

There are several things you need to know. Email is quite a broad topic.

  1. You need to have a MTA (Mail Transfer Agent), also called mail server, installed on your server. I'd recommend Postfix, as it is very commonly used, but there are people who prefer Exim as a MTA. You can learn more about Postfix configuration at http://www.postfix.org/BASIC_CONFIGURATION_README.html

  2. You need to have some basic knowledge about setting up DNS. You need to set up either A or MX record for example.com pointing to your server. If you already have an A record (maybe it's already set up for your website), then you don't necessarily need a MX record. However, some sites don't like to send or receive mail from domains without a MX record, so it's best to have both, even in case when the MX record is technically superfluous.

You should also make sure that your forward domain matches the reverse domain. The forward domain (A record) is when someone wants to access example.com, their computer is asking the DNS server for an IP address and gets some address A.B.C.D. Reverse domain (PTR record) is when a computer gives the DNS server that IP address A.B.C.D and asks about a corresponding domain (mail servers do this all the time). These two are not the same because they are configured in two different places. Forward domain is configured at the place where you have your domain registered; reverse domain is configured at the place where you have rented your server. You need to ensure that they match, otherwise when you try to send mail, the receiving servers may consider you a spammer and reject or filter out your mail.

Points 1) and 2) should be sufficient to receive mail on your server. However, you also need some way to read it :)

  1. If you have SSH access to your server (probably you do), the simplest method to access your mail is to install a console-based email program on the server, like for example Mutt. Then you login to the server via SSH, start the program by typing mutt and can read and send emails. However, you are limited to a text-only interface and it is for example hard to send or download attachments (because you need to independently transfer them between server and your PC).

  2. To be able to use email program on your PC, you must install another piece of software besides MTA on your server. This is the IMAP server. Email programs connect to IMAP server to be able to read mail. I'd recommend Dovecot as the IMAP server, it works very well with Postfix. If you install an IMAP server you will be able to use email programs like Thunderbird or Outlook. However, there is one more thing you have to configure for sending mail from such a program - this is the SMTP authentication. It requires cooperation between your MTA (Postfix) and IMAP server (Dovecot) - you can find more information here.

  3. If you need a webmail interface like Gmail, there is one more thing you need to install on your server - that's the webmail application. There are many of them, I don't know much about them as I use mostly methods 3) and 4) mentioned above to access my mail. One webmail I have used and consider it good is Roundcube. Webmail applications usually require IMAP server to be installed, as they also access mail via IMAP.

  4. Finally, once you get it all working, you may notice that big email providers like Google or Microsoft might not accept mail from your domain or they will accept it, but put it to recipient's Spam folder. This is because they require some conditions to be met to satisfy their antispam systems. There are a few more things that need to be configured. This is for example what Google requires from senders.

It is not said that without satisfying these conditions, your mail will not be delivered to Google or Microsoft. You can have luck and everything will be OK. However, if it turns out that you don't have luck, you need to do all of this and then probably wait until Google and Microsoft consider you being a legitimate sender...

  • You should have a SPF record set up for your domain in the DNS
  • You should install an additional piece of software into your MTA that will DKIM sign the outgoing messages, and you need to publish your DKIM keys in the DNS for your domain
  • Finally, you should publish a DMARC record for your domain in the DNS.

All these things are explained in more detail in Google document linked above.