DNS

DNS is short for "domain name system" and is the magic on the internet that turns names like "www.workaround.org" into IP addresses like "212.12.58.129". If you want to receive email for a certain domain you need to be in charge of its "zone" which contains the actual "records". The zone file for "workaround.org" contains an A (address) record so that you can view this website. And among other records it contains an MX (mail exchanger) record telling which servers should be used when someone sends an email to devnull@workaround.org. This is a simplified extract of the zone file:

IN  TXT  "v=spf1 ip4:212.12.58.128/27 -all"
IN  MX      10 mx1.workaround.org
IN  MX      20 mx2.workaround.org
IN  MX      30 mx3.workaround.org
IN  MX      40 mx4.workaround.org
IN  A    212.12.58.129

The "IN" is the class of the records. On the internet it's always "IN".  The second column designates the record type:

How other mail servers find your mail server

Imagine that some mail server on the internet has an email for your domain in its queue. Now it needs to find out which IP address to connect and send the email via the SMTP protocol. First it does a DNS lookup for an MX record of the domain used in the email address. If it gets several addresses back it will try the servers mentioned in the response beginning with the servers having the highest priority (=smallest number) assigned. If it doesn't reach it then it will try the next mail server in order. If the mail server did not find any MX entries then it will try another DNS lookup for an A record and send the email there.

Let's try an example. You want to send an email to devnull@workaround.org. So the domain is apparently the "workaround.org" part. Is there an MX entry? You can try that yourself using the dig tool. ("host" or "nslookup" will work equally well. Install dig using "aptitude install dnsutils" if you haven't already.)

$> dig +short workaround.org mx
30 mx3.workaround.org.
40 mx4.workaround.org.
10 mx1.workaround.org.
20 mx2.workaround.org.

So there are four mail servers in question. The one with the highest priority (10) is mx1.workaround.org. Let's find out its IP address by asking for an A record of this hostname:

$> dig +short mx1.workaround.org
212.12.58.158

The mail server will now try to reach the mail server on this IP address on TCP port 25 (SMTP) and attempt to deliver the email. Incidentally (or maybe not) the mail server does not appear to be reachable. There are no more mail servers with priority 10 so it tries the next best mail server mx2.workaround.org with priority 20. Which IP address does it have?

$> dig +short mx2.workaround.org
212.12.58.129

This mail server works better and the SMTP connection is established and the email delivered.

So in order to receive email for a domain you need to set at least one MX entry in its zone to point to your mail server. Note that an MX entry points to a hostname - never an IP address. If you can't add MX entries then an A record will do, too.