12.1 Mail Delivery over the Internet
Prev | Chapter 12 Sending and Receiving Mail | Next

## 12.1 Mail Delivery over the Internet

Understanding the basic principles of mail delivery over the Internet will help you correctly set your mailserver. This chapter gives a brief overview of the most important information on this topic. Experienced network administrators can skip this chapter.

### MX Records

Appropriate records must be entered into the DNS (DNS is a world-wide distributed database of domain names) for each Internet domain. One of these records is called a MX record (Mail eXchanger or the mailserver). An MX record for the domain `company.com` might look like this:

    company.com               MX      10      mail.company.com
                              MX      20      smtp.provider.com
    mail.company.com          A               215.75.128.33
    smtp.provider.com         A               215.75.128.1

These records indicate that the mailserver with a preference of `10` is a computer named `mail.company.com` and the server with a preference of `20` is a computer named `smtp.isp.com`. Preference means value of the server. The lower the preference the higher the priority of that server — this implies that the server `mail.company.com` is the highest priority mail server for the domain `company.com` and the server `smtp.isp.com` is the second highest priority mail server for the domain. Arbitrary number of MX records can be defined for the given domain. If two or more records have the same priority, then one of these servers is chosen randomly (load balancing).

The other two records are `A` type (Address). These tell us which IP address is assigned to a given computer (a MX record can only be assigned to a DNS name, but not an IP address).

### Email Delivery

How does an email travel from the sender to the addressee?

The sender's mail client sends the email to its SMTP server. The server checks the recipient's address and if the domain contained within the address is qualified as local the email is saved directly into the appropriate mailbox. If the domain is not local, the SMTP server finds the name of the primary mailserver (SMTP) for the target domain from the DNS (by sending a DNS request) and sends the email to this server. This saves it to a mailbox from which the recipient downloads it using his/her email client.

If the primary mailserver for the target domain is not accessible, the sending SMTP server tries to contact the secondary server (the server with the next priority) and send the email there. If no server listed in the MX record for the target domain is accessible the SMTP server will try to send the mail again repeatedly in defined intervals. If it does not succeed after a certain time the email is returned to the sender as undeliverable.

If, for example, only the secondary server is accessible the email is sent to this secondary server. In principle, any SMTP server can function as a secondary (tertiary, etc.) server for a domain.

### Sending Email via a Different SMTP Server (Relaying)

There is also another way email can be delivered to addressees. The client sends the email message to its SMTP server. This server forwards it to another SMTP server which delivers it to the target domain as described above. This method of delivering email is known as relaying (passing to the relay server).

The advantage of this relaying is that sending email is an on-off action. Furthermore, email can be placed in a queue and sent in defined time intervals. The sending SMTP server does not need to ask the DNS about the target domains' mailservers or try to send the email again if the target servers are inaccessible. This is important mainly for slow or dial-up Internet connections and it can significantly decrease costs of such connections.

Most SMTP servers on the Internet are protected against relaying to prevent misuse of servers for sending spam email. If you wish to send email via a different SMTP server, you should contact the server's administrator and ask them that relaying be enabled for you (usually based on checking your IP address or using username/password authentication).

### ETRN Command

ETRN is a command of SMTP protocol. It serves for requesting emails stored on another SMTP server. Typically, it is used in the following situations:

1. The client has its own domain (e.g. `company.com`) and his server is connected to the Internet via a dial-up line. Dial-up must have a fixed IP address. The primary MX record for the domain `company.com` is directed to the ISP's SMTP server (e.g. `smtp.isp.com`). When it is connected to the Internet, the client's SMTP server sends an ETRN command that informs that it is online and ready to receive mail. If the primary server has some emails for the given domain, then it sends them. If not, it can send a negative response or it need not reply at all. That's why the client's server must have the timeout to specify how long it will wait for the response from the primary server.

   ### Note

   The primary server will create a new connection to the client's server after the ETRN command reception. This connection is used for mail transmission. If the client's server is protected by firewall, TCP port 25 must be accessible (open) to the Internet.

2. Let's suppose that the domain `company.com` has a primary server `smtp.company.com` and a secondary server `smtp2.company.com`. Both servers are permanently connected to the Internet. Under normal circumstances, all messages for this domain are sent to the primary server `smtp.company.com`. If failure of this server occurs (overloading, disconnected line etc.), all messages are sent to the secondary server `smtp2.company.com`. When the primary server becomes available it can send an ETRN command to the secondary server to request stored mails. Communication is the same as in the previous example (for detailed description of secondary SMTP server settings, see chapter 7.10 Setting up the backup mail server).

   Mail delivery is faster and more reliable in this way than waiting till the secondary server sends the mails itself (see section Email Delivery). In addition, the ETRN command can be used also for dial lines.

### domain mailbox

The domain's primary mailserver does not always need to be the server where user mailboxes are stored. If the company to which the domain is registered connects to the Internet via a dial-up line, it can have a Domain Mailbox at its ISP. A domain mailbox is an account where mail for the entire domain is stored. The company's mailserver can retrieve mail from this mailbox (in certain time intervals) and sort the email into individual user mailboxes. The ISP's SMTP server, where the domain mailbox is stored, is listed as the primary mailserver for the company's domain in the MX records.

Domain mailbox receives the messages via SMTP protocol. Each message therefore contains the body as well as the SMTP envelope. Only the body of the message is downloaded to the domain mailbox. The envelope information is copied to a message header (depending on the domain mailbox settings).

Kerio MailServer performs authentication to the domain mailbox. Then it downloads messages via POP3 and sorts them according to the rules specified in Kerio MailServer. In order for the rule to be sorted properly, it must contain the recipient information (either in any of the special message headers or in the To or Cc fields). If there is no information about the recipient contained in the message, the system returns it to the sender. However, if a special sorting rule is created in Kerio MailServer (see chapter 12.4 remote POP3 mailboxes), the messages without any recipient data will be stored in a predefined user mailbox.

### Note

It is recommended to specify a special `X-Envelope-To:` header for message sorting, because it contains information about recipients. This helps you avoid situations where a message addressed to multiple users is delivered several times according to the number of recipients.

### Access of email clients to user accounts

User can use various methods to access their email accounts:

POP3

  POP3 (Post Office Protocol version 3) is an Internet protocol used for downloading of email from a server to another server (see the Domain Mailbox section) or to an email client. POP3 protocol is defined in RFC 1939.

  POP3 protocol works on client-to-server basis. Connection is always established by the client, then requests and responses of the client and of the server take regular turns until the connection is closed. As soon as the client initializes the connection and is successfully authenticated by name and password, it is possible to work with the email (download it to the client, delete it, etc.).

  Under usual circumstances, Kerio MailServer works as a server. If, however, it downloads email from remote POP3 accounts, it can also work as a client.

  POP3 protocol is quite obsolete. The protocol can download email to a client application and can work with merely one folder (INBOX). This means that any message moved to another folder would disappear since moved out of the only folder available. And the other way round. If a user can access multiple folders and moves a message from Inbox to another one, the message cannot be uploaded to the client application. Therefore, it is generally recommended to use IMAP, a more modern protocol. Advantages of the IMAP protocol can be seen in the comparative table 12.1 POP3 and IMAP comparison.

  The only advantage of this protocol might be low demands on server's disk space. Users download their email to their local disks and there it is possible to sort messages in folders, remove items, etc. Therefore, POP3 accounts are used especially for freemail services where users have mailboxes with capacity of a few megabytes and download their email to their local disks regularly. Another advantage is the good availability of offline transactions which can be used if connection to the Internet is time-limited. Nowadays, however, most of email clients work well in their offline modes both with POP3 and with IMAP accounts.

IMAP

  IMAP (Internet Mail Access Protocol) is an Internet protocol used for connections to email servers, as well as for reading of messages and for other email transactions. IMAP protocol is defined in RFC 3501.

  In addition to downloading email to users' local hosts, IMAP protocol enables administration of email account on the server. It is, therefore, possible to access email accounts from various client stations. Unlike POP3, IMAP protocol allows keeping email on the server and handling it there (reading, removing, sorting to folders). It is also possible to keep the email stored in the email client. This solution is helpful especially if users have a time-limited Internet connection or can be connected to the server only temporarily or irregularly and need to work with their email offline. Once reconnected to the network, folders on the server and on the client are synchronized.

  Another difference is that in case of IMAP protocol, email can be handled while items are downloaded to the local store. In case of IMAP protocol, email headers are downloaded first and user can select any of them to be opened as the first. When the message is selected, it will be considered as a high-priority item and it can be read, moved to another folder or otherwise manipulated while the other email is being downloaded.

  POP3 | IMAP
  --- | ---
  both secured and unencrypted (POP3S) | both secured and unencrypted (IMAPS)
  enables authorization | enables authorization
  works with a single folder only | allows manipulations with folders (e.g. moving messages between folders), all folders are created and stored on the server
  downloads entire messages (messages are displayed one by one as downloaded from the server) | downloads email headers first, message bodies later
  synchronous (it is not possible to handle email while it is being downloaded, one must wait until the email is available on the local disk) | asynchronous (individual messages can be handled while email is being downloaded)
  only one client can be connected to the account | multiple clients can be connected to the account

  Table 12.1. POP3 and IMAP comparison

Access via the MAPI interface (MS Outlook)

  Kerio MailServer enables access to email via the MAPI interface. MAPI (Messaging Application Programming Interface) is a versatile interface for email transmission, developed by Microsoft. It is a software interface that enables any MAPI client to communicate with any mailserver (MS Outlook and Kerio MailServer in this case).

  To enable traffic via the MAPI interface, Kerio Technologies developed Kerio Outlook Connector, a special application which is installed on a client and work as an MS Outlook extension. MS Outlook extended by Kerio Outlook Connector handles email in the same manner as the IMAP protocol, and it even allows additional options.

  Thanks to this modification, MS Outlook is able to work with groupware data (contacts, calendar, tasks, notices) stored in Kerio MailServer. The main benefit of the shared data store is that the data is available via the Internet anywhere necessary. To access the data, you'll need just an Internet connection and a web browser (the Kerio WebMail interface), MS Outlook with the Kerio Outlook Connector.

  MS Outlook with the Kerio Outlook Connector also enables better scheduling of meetings and tasks (the Free/Busy calendar) as well as sharing of various types of data (shared and public folders).

  For more information on Kerio Outlook Connector, see chapter 33.2 Kerio Outlook Connector.

Access via the WebDAV interface (MS Entourage)

  Kerio MailServer supports the WebDAV interface (Web Distribution Authoring and Versioning) which can also be used for accessing email accounts. Using WebDAV, users can group-edit and organize files located on servers.

  Support for the WebDAV interface in Kerio MailServer enables connection of MS Entourage. MS Entourage is an MS Office 2004 for Mac email client which can use POP3, IMAP protocols and the WebDAV interface to connect to email servers.

  Users who want to use MS Entourage to connect to Kerio MailServer can use a special interface originally developed for communication with MS Exchange. In MS Entourage, the interface is represented as an Exchange account and it is based on WebDAV traffic.

  The WebDAV interface in MS Entourage provides similar options as the Kerio Outlook Connector. This implies that, in addition to email manipulation, it enables working also with groupware data (email, calendars, contacts, public folders), it supports Free/Busy server, etc.

  In older versions, IMAP protocol was used to access email and the WebDAV interface was used for other folder types. MS Entourage 2004, however, uses WebDAV also to access to email folders.

  Cooperation of Kerio MailServer with MS Entourage is supported directly. This means that no extension is required to be installed at client stations. It is only necessary to set correctly the basic parameters for an Exchange account.

  To learn more on MS Entourage and its correct settings, see chapter 38 MS Entourage support.

Prev | Up | Next
Chapter 12 Sending and Receiving Mail | Contents | 12.2 SMTP server