Revision: $Revision: 1006 $ ($Date: 2012-10-11 11:09:11 +0200 (Thu, 11 Oct 2012) $)
This objective has a weight of 7 points and contains the following objectives:
Candidates should be able to manage an e-mail server, including the configuration of e-mail aliases, e-mail quotas and virtual e-mail domains. This objective includes configuring internal e-mail relays and monitoring e-mail servers.
Candidates should be able to implement client e-mail management software to filter, sort and monitor incoming user e-mail.
Candidates should be able to install and configure POP and IMAP daemons.
Candidates should be able to manage an e-mail server, including the configuration of e-mail aliases, e-mail quotas and virtual e-mail domains. This objective includes configuring internal e-mail relays and monitoring e-mail servers.
Configuration files for postfix.
Basic knowledge of the SMTP protocol, sendmail, and exim.
| Configuration files and commands for postfix |
| Basic configuration of sendmail |
/etc/aliases |
/etc/mail/* |
/etc/postfix/* |
| sendmail emulation layer commands |
/var/spool/mail |
| mail-related logs in /var/log |
Since April 2001 RFC2821 is in use for describing the SMTP protocol. This RFC obsoletes RFC821, RFC974 and updates RFC1123.
When an SMTP client has a message to transmit, it establishes a two-way transmission channel to an SMTP server. The responsibility of an SMTP client is to transfer mail messages to one or more SMTP servers, or report its failure to do so.
The means by which a mail message is presented to an SMTP client, and how that client determines the domain name(s) to which mail messages are to be transferred is a local matter, and is not addressed by this document. In some cases, the domain name(s) transferred to, or determined by, an SMTP client will identify the final destination(s) of the mail message.
Detailed information can be found at:
RFC2821. For demonstration purposes an SMTP session can be done by using a telnet
connection to a mail server:
telnet mx1.unix.nl 25
Connected to mx1.unix.nl (213.154.248.146).
Escape character is '^]'.
220 mx1.unix.nl ESMTP Exim 4.63 Thu, 12 Aug 2010 08:50:30 +0200
ehlo snow.nl
250-mx1.unix.nl Hello mx1.unix.nl [81.23.226.83]
250-SIZE 52428800
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
Using telnet <smtp servername> 25 we make the initial contact with the SMTP server, in this example I used mx1.unix.nl as the server. The server responds with the maximum message size, the pipelining, and the authentication capabilities of the server, in this case AUTH PLAIN LOGIN. The server is also able to use STARTTLS and the HELP function is available.
| message size: when the size of the message the client wishes to send exceeds the set limit, the SMTP transaction will be aborted with an ERROR code pipelining. Also, when enabled, an SMTP client can transmit a group of SMTP commands (eg. RSET, MAIL FROM, RCPT TO) without waiting for a response from the server. |
| AUTH PLAIN LOGIN: the SMTP server is capable of handling a plain password/username authentication. This can be handy for mobile devices using the SMTP server while originating from different IP addresses. |
| STARTTLS: The SMTP protocol of itself doesn't include any form of encryption. With STARTTLS the communciation can be encrypted using certificates and is fully described in RFC3207. |
Since we have establised the initial connection we can now proceed:
mail from: mwijtkamp@snow.nl
250 OK
rcpt to: info@unix.nl
250 Accepted
The server responds with 250 Ok but when, for example, the MAIL FROM command is followed by a misformatted or incomplete email address the server responds with 501:
sender address must contain domain or similar error. With RCPT TO
emailaddress the destination of the message is given. If the recipient's address is accepted the server responds: 250 Accepted
Now the mailserver knows who we are, and to whom we wish to transmit a message. The email client also knows what the SMTP server is capable of. We then proceed with the transmission:
data
354 Enter message, ending with "." on a line by itself
mail from: Marc <mwijtkamp@snow.nl>
From: <mwijtkamp@snow.nl>
To: Info <info@unix.nl>
Subject: Demo messages
Date: 12-02-2010 08:53:00
MesssageID: 31231233@snow.nl
This is a demonstration mesage.
.
250 OK id=1OjReS-0005kT-Jj
quit
With the DATA command we proceed with the content of the message. The server responds with: 354 Enter message, ending with "." on a line by itself
Then the message content is entered starting with the message-headers. These headers are used by the email client. In this example Mail From, To, Subject, Date and Message-ID is used. Message-ID is an unique identifier generated by the SMTP client. These headers are required as described in RFC822.
After the headers have been entered, a blank line indicates that the actual text of the message commences. The message ends, as the DATA command response has already indicated, with a "." (without the quotes) on a blank line. The server responds with: 250 OK id=1OjReS-0005kT-Jj. The id is a unique SMTP server identifier and can be used for troubleshooting.
When fighting spam some SMTP servers can check whether a message is RFC822 compliant. Regular SMTP clients are RFC822 compliant, but spammers often use a not so regular SMTP client and thus send malformed messages.
| Basic sendmail configuration steps are: |
| 1 Download Sendmail |
| 2 Set up Sendmail |
| 3 Configure Sendmail |
| 4 Build the Sendmail User Table |
| 5 Add your domain names to Sendmail |
| 6 Test your configuration file |
Basic configuration of sendmail is described at: Sendmail basic installation.
An installation and operation guide for sendmail 8.12 can be found at: Sendmail installation and operation guide.
Sendmail can be either built from source or installed as sendmail binaries. With sendmail you must build a run-time configuration file. This is a file that sendmail reads when it starts up that describes the mailers it knows about, how to parse addresses, how to rewrite the message header, and the settings of various options. Although the configuration file can be quite complex, a configuration can usually be built using an M4-based configuration language. Assuming you have the standard sendmail distribution, see cf/README for further information.
The sendmail configuration files are processed by m4 to facilitate local customization; the directory cf of the sendmail distribution directory contains the source files. This directory contains several subdirectories:
Both site-dependent and site-independent descriptions of hosts. These can be literal host names (e.g., ucbvax.mc) when the hosts are gateways or more general descriptions (such as generic-solaris2.mc as a general description of an SMTP-connected host running Solaris 2.x. Files ending .mc (``M4 Configuration'') are the input descriptions; the output is in the corresponding .cf file. The general structure of these files is described below.
Site-dependent subdomain descriptions. These are tied to the way your organization wants to do addressing. For example, domain/CS.Berkeley.EDU.m4 is our description for hosts in the CS.Berkeley.EDU subdomain. These are referenced using the DOMAIN m4 macro in the .mc file.
Definitions of specific features that some particular host in your site might want. These are referenced using the FEATURE m4 macro. An example feature is use_cw_file (which tells sendmail to read an /etc/mail/local-host-names file on startup to find the set of local names).
Local hacks, referenced using the HACK m4 macro. Try to avoid these. The point of having them here is to make it clear that they smell.
Site-independent m4(1) include files that have information common to all configuration files. This can be thought of as a #include directory.
Definitions of mailers, referenced using the MAILER m4 macro. The mailer types that are known in this distribution are fax, local, smtp, uucp, and usenet. For example, to include support for the UUCP-based mailers, use MAILER(uucp).
Definitions describing various operating system environments (such as the location of support files). These are referenced using the OSTYPE m4 macro.
Local UUCP connectivity information. This directory has been supplanted by the mailertable feature; any new configurations should use that feature to do UUCP (and other) routing. The use of this directory is deprecated.
Make sure the m4 utility is available at the server. With the m4 utility the .mc macro files can be converted to a sendmail.cf file. The recommended method to configure sendmail is to edit the macro files. And not the sendmail.cf file itself.
Details of sendmail installation files can be seen at: Sendmail installation and operation guide.
/etc/mail/sendmail.cf
- Main sendmail configuration file
/etc/mail/access
- Used to allow or deny access to systems and users.
To create a new access map:
$ makemap hash access < access
In the accesss file different actions can be defined:
Accept mail even if other rules in the running ruleset would reject it, for example, if the domain name is unresolvable. "Accept" does not mean "relay", but at most acceptance for local recipients. That is, OK allows less than RELAY.
Accept mail addressed to the indicated domain or received from the indicated domain for relaying through your SMTP server. RELAY also serves as an implicit OK for the other checks.
Reject the sender or recipient with a general purpose message.
Discard the message completely using the $#discard mailer. If it is used in check_compat, it affects only the designated recipient, not the whole message as it does in all other cases. This should only be used if really necessary.
This can only be used for host/domain names and IP addresses/nets. It will abort the current search for this entry without accepting or rejecting it but causing the default action.
/etc/mail/local-host-names
localhostnames can be defined in the local-host-names file.
Add each domain that is to be considered a local account into /etc/mail/local-host-names.
/etc/mail/virtusertable
Used to map incoming email to a local account. With virtusertable, messages sent to one account can be distibuted to two users.
Also a "catchall" email address can be set up to route all mistyped email to one particular user to create a new virtusertable.
$ makemap hash /etc/mail/virtusertable < sourcefile
/etc/mail/genericstable
Used for outbound mail.
Can be used to rewrite local usernames so they appear to have originated from a different host or domain.
/etc/mail/genericsdomain
Populate this file with the hostname --long command.
# hostname --long > genericsdomain
/etc/mail/mailertable
Used to route email from remote systems.
/etc/mail/domaintable
Can be used to make a transition from an old domain name to a new one.
/etc/mail/aliases
Used to redirect mail for local recepients
newaliases needs to be run after any change in this file.
# newaliases
If any update is made in one the of the configuration files sendmail needs to reload the files:
# killall -HUP sendmail
Starting with sendmail version 8.9, sendmail does not relay by default. When using an older sendmail version, make changes in sendmail.cf or access file to make sure that sendmail does not relay. Antirelaying tips are described at:
sendmail can be run in test mode. Use the -b and -t options to do this. You need to run this as root
# sendmail -bt
Make sure that the MX for the MTA's are available in DNS. This can be checked with:
$ dig MX somedomain.com
As mentioned before this is not the recommended way.
DS somedomainname
The DS parameter points to the enterprise mail server in most cases.
Exim is a message transfer agent (MTA) developed at the University of Cambridge for use on Unix systems connected to the Internet. Exim can be installed in place of Sendmail, although the configuration of Exim is quite different. Also see exim.org for more detailed information.
The exim4-config_files man page contains descriptions for each of these files. Exim comes with an exim.conf template. Just edit this config file for your environment. Some example config files can be found at the exim new users site:
The default location for the postfix configuration files is /etc/postfix,
there we find the two main configuration files main.cf and
master.cf. After making changes to the configuration of postfix you
need to reload postfix using: postfix reload.
Before postfix can be used it needs to know:
| what domains to receive mail for |
| which domain name to use for outbound mail |
| which domain(s) postfix is allowed to relay mail for |
| what delivery method to use |
The myorigin parameter specifies the domain that
appears in outgoing email. This can be done using one of the following examples:
myorigin = $myhostname
or
myorigin = $mydomain
The $myhostname or $mydomain are replaced by postfix with the according
hostname or domain name of the server it is running on.
Postfix needs to know also for which domain(s) it will receive mail for. Therefore the
parameter mydestination is used. There can be more than one domain specified.
The multiple domain names can be seperated using a whitespace or a comma. Also a pattern
can be used to point to a lookup table (hash, btree, nis, ldap or mysql)
mydestination = $mydomain, localhost.$mydomain, hash:/etc/postfix/moredomains
You have to include $mydomain when the server is used as a mailserver
for the entire domain.
The default configuration of postfix will try to deliver incoming mail to authorized
destinations only. Using the relay_domains parameter we can control for which domains postfix relays to.
relay_domains = (safe: never forward mail from strangers)
relay_domains = $mydomain (forward mail to my domain and subdomains)
Default postfix tries to deliver directly to the internet depending on the domain name of
the destination address in the mail message. Using the relayhost parameter we can
specify to use another SMTP server as relay:
relayhost =
This is the default, direct delivery to the internet, or using an other ISP SMTP server:
relayhost = mail.myisp.com
Postfix uses the syslog daemon for its logging. The syslog configuration itself
is out of the scope of this document. When /etc/syslog.conf is
configured as in the example below, postfix's log is written
to /var/log/maillog. Error messages are, in this example,
redirected to the console.
mail.err /dev/console
mail.debug /var/log/maillog
Using egrep '(reject|warning|error|fatal|panic):' /var/log/maillog
will help you to find any problems postfix encountered
Generally a postfix server is final destination for a limited number of domains. But postfix
can also be configured to handle mail for additional domains which are different from, for example,
the domain in which the postfix server is located. These destinations are called virtual hosts.
Using the virtual_alias_domains parameter we can specify for which virtual
hosts we wish to receive mail. The format of the parameters is the same as in the
samples above. Separate multiple virtual hosts using a space or a comma and also
a link to a (hashed) file on disk is possible:
virtual_alias_domains = example.com, anotherexample.com
or when using a hashed file (using the postmap utility):
virtual_alias_domains = hash:/etc/postfix/virtual
The content of /etc/postfix/virtual can be:
postmaster@example.com peter
info@anotherexample.com gerda
sales@example.com petra
@example.com jim
In the above example peter receives the postmaster@example.com email. Gerda receives the info@anotherexample.com email and the sales@example.com goes to petra. The last line is a "catch all" rule, all email for example.com without a valid destination goes to jim.
Use postmap /etc/postfix/virtual to create the hashed file and issue a
postfix reload after updating the virtual file.
For new messaging systems and to allow mail delevery there is a need for sendmail emulation. Some of the newer MTA's replace the sendmail binary. eg. exim. Sendmail emulators are used to ensure the compatibility with messaging systems that use sendmail and SMTP for mail delivery.
sSMTP, fetchmail and milters are examples of this.
simple SMTP is a sendmail replacement with one simple configuration file ssmtp.conf
fetchmail can fetch mail from different mailservers and put them into one mailbox.
mail filter. It is an extension to sendmail or postfix. It allows administrators to add mail filters.
More infomation on mail filters can be found at: milter.org An interactive catalog of sendmail filters.