Mail server

From ArchWiki
Jump to: navigation, search

A mail server consists of multiple components. A mail transfer agent (MTA) receives and sends emails via SMTP. Received and accepted emails are then passed to a mail delivery agent (MDA), which stores the mail in a mailbox (usually in mbox or Maildir format). If you want users to be able to remotely access their mail using email clients (MUA), you need to run a POP3 and/or IMAP server.

+---------+  SMTP  +---+   +---+               +----------------+
|Other MTA| <----> |MTA| --|MDA|-> Storage <-- |POP3/IMAP server|
+---------+        +---+   +---+               +----------------+
                     ^                                 ^
                     |     SMTP    +---+               |


All of these software except Sendmail include a mail delivery agent.

  • Exim — A highly configurable mail transfer agent. || exim
  • OpenSMTPD — A mail transfer agent, part of the OpenBSD project. || opensmtpd
  • Postfix — A mail transfer agent, meant to be fast, easy to administer, and secure. || postfix
  • Sendmail — A well-known mail transfer agent. || sendmailAUR

POP3/IMAP servers

  • Courier — A mail transfer agent, providing POP3, IMAP, webmail and mailing list services as individual components. || courier-mtaAUR
  • Cyrus IMAP — A mail transfer agent with a custom mail spool format, provides POP3 and IMAP services. || cyrus-imapdAUR
  • Dovecot — An IMAP and POP3 server written to be secure, fast and simple to set up. || dovecot || imap

Standalone MDAs

  • fdm — A simple program for delivering and filtering mail. || fdm
  • Procmail — A program for filtering, sorting and storing email (unmaintained). || procmail

See also Wikipedia:Comparison of e-mail servers.


Purpose Port Protocol Encryption
Accept mail from other MTAs. 25 SMTP STARTTLS
Accept submissions from MUAs. 587 SMTP STARTTLS
465 SMTPS implicit TLS
Let MUAs access mail. 110 POP3 STARTTLS
995 POP3S implicit TLS
993 IMAPS implicit TLS

Note that implicit TLS is more secure than STARTTLS because the latter is vulnerable to man-in-the-middle attacks, for more information see [1] and RFC:8314.

MX record

If you want to receive mail, you need to set an MX record of your domain name to point to your mail server. Usually this is done from the configuration interface of your domain provider.

A mail exchanger record (MX record) is a type of resource record in the Domain Name System that specifies a mail server responsible for accepting email messages on behalf of a recipient's domain.

When an e-mail message is sent through the Internet, the sending mail transfer agent queries the Domain Name System for MX records of each recipient's domain name. This query returns a list of host names of mail exchange servers accepting incoming mail for that domain and their preferences. The sending agent then attempts to establish an SMTP connection to one of these servers, starting with the one with the smallest preference number, delivering the message to the first server with which a connection can be made.

Note: Some mail servers will not deliver mail to you if your MX record points to a CNAME. For best results, always point an MX record to an A record definition. For more information, see e.g. Wikipedia's List of DNS Record Types.


Warning: If you deploy TLS, be sure to follow Server-side TLS to prevent vulnerabilities.

To obtain a certificate, see OpenSSL#Certificates.


There are various email authentication techniques.

Sender Policy Framework

From Wikipedia:

Sender Policy Framework (SPF) is an email validation protocol designed to detect and block email spoofing by providing a mechanism to allow receiving mail exchangers to verify that incoming mail from a domain comes from an IP Address authorized by that domain's administrators.

To allow other mail exchangers to validate mails apparently sent from your domain, you need to set a DNS TXT record as explained in the Wikipedia article. To validate incoming mail using SPF you need to configure your mail transfer agent to use a SPF implementation. There are several SPF implementations available, libspf2, perl-mail-spf and perl-mail-spf-query can be found in the official repositories.

SPF validation support
Courier Yes, built-in
Postfix Yes
Sendmail through Milter and spfmilter-acmeAUR
Exim experimental, requires libspf2
Cyrus IMAP ?

The following websites let you validate your SPF record:

Tip: SPF can even be helpful for domains not used to send email. Publishing a policy like v=spf1 -all makes any mail server enforcing SPF reject emails from your domain name, thus preventing misuse.

Sender Rewriting Scheme

The Sender Rewriting Scheme (SRS) is a secure scheme to allow forwardable bounces for server-side forwarded emails without breaking the Sender Policy Framework.

For Postfix, see Postfix#Sender Rewriting Scheme.


DomainKeys Identified Mail (DKIM) is a domain-level email authentication method designed to detect email spoofing.

Available DKIM implementations are OpenDKIM and dkimproxy.

Testing websites

There are several handy web sites that can help you test DNS records, deliverability, and encryption support.

Tips and tricks

Most mail servers can be configured to strip users' IP addresses and user agents from outgoing mail.

Available extras that can usually be integrated are: