211.1. Using e-mail servers

211.1 Using e-mail servers

Weight: 4

Description: 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.

Key Knowledge Areas:

  • Configuration files for postfix

  • Basic TLS configuration for postfix

  • Basic knowledge of the SMTP protocol

  • Awareness of sendmail and exim

Terms and Utilities:

  • Configuration files and commands for postfix

  • /etc/postfix/

  • /var/spool/postfix/

  • sendmail emulation layer commands

  • /etc/aliases

  • mail-related logs in /var/log/

What is e-mail ?

Electronic mail (email or e-mail) is a method of exchanging messages ("mail") between people using electronic devices. Email first entered limited use in the 1960s and by the mid-1970s had taken the form now recognized as email. Email operates across computer networks, which today is primarily the Internet. As its obvious e-mail is pretty old method of communication and some times it is said that the e-mail is as old as the internet itself! But nowadays no successfull bussiness can live with out that.

How e-mail Works?

Email is based around the use of electronic mailboxes. When an email is sent, the message is routed from server to server, all the way to the recipient's email server.

1.First the User open its mail box using using one of many mail client applications (Like Thunderbolt, Evolution, SquirrelMail, ...) (which is Called MUA, Mail user Agent) and send an e-mail.

2.Then Mail Submission Agent(MSA) receives electronic mail messages from a mail user agent (MUA) and cooperates with a mail transfer agent (MTA) for delivery of the mail.

3.The message is sent to the mail server tasked with transporting emails (called the MTA, for Mail Transport Agent) to the recipient's MTA. On the Internet, MTAs communicate with one another using the protocol SMTP, and so are logically called SMTP servers (or sometimes outgoing mail servers).

  • SMTP (Simple Mail Transfer Protocol). It is a protocol that really defines how e-mail is transfered and saved and is a part of the TCP/IP application layer as well as settings rules that e-mail applications follow.

4.The recipient's MTA then delivers the email to the incoming mail server (called the MDA, for Mail Delivery Agent), which stores the email as it waits for the user to accept it.(Sometimes MTA can also function as an MDA)But often (procmail for example) , They are independent applications that can also filter mail(like spam).

There are two main protocols used for retrieving email on an MDA:

  • POP3 (Post Office Protocol), which is used by MUAs, for retrieving email and, in certain cases, leaving a copy of it on the server.

  • IMAP (Internet Message Access Protocol), which is used by MUAs,for coordinating the status of emails (read, deleted, moved) across multiple email clients. With IMAP, a copy of every message is saved on the server, so that this synchronization task can be completed.

    Both of those can be secured with TLS or SSL Certificates, so it is encrypted at some levels between the server and end user client (MUA).

MX Record

MX records are the mail DNS record (we discussed about earlier in DNS Course). These records are used by MTAs to determine the authorative mail server for any particular e-mail message.

MUA

Mail User Agent. This is whatever application we use to create and send e-mail (Like Thunderbolt, Evolution, SquirrelMail, etc).

MSA

Mail Submission Agen. Acts as an intermediary or gateway between the MUA and an MTA to strat the transfer of e-mail.

MTA

Mail Transfer Agent. Accepts e-mail from the MUA and sends it (if needed) to the receiving mail address (could be another MTA if this is not the destination.

Mail Transfer Agents(MTAs) for Linux

Lets look at a round up of the best and most used MTA’s on Linux mail servers:

1.Send Mail

Sendmail now known as proofpoint (after Proofpoint, Inc acquired Sendmail, Inc) is by far the most popular and one of the oldest MTA on the Linux server platform. Sendmail has a lot of limitations though, in comparison to modern MTAs.

Because of its complicated configuration steps and demands, and weak security mechanisms, many new MTAs have come up as alternatives to Sendmail, but importantly, it offers everything to do with mail on a network.

2.Exim

Exim is a free MTA developed for Unix-like operating systems such as Linux, Mac OSX, Solaris and many more. Exim offers a great level of flexibility in routing mail on a network, with outstanding mechanisms and facilities for incoming mail monitoring.

Its notable features include among others:

  • No support for POP and IMAP protocols

  • Supports protocols such as RFC 2821 SMTP and RFC 2033 LMTP email message transport(LMTP is an alternative to normal SMTP for situations where the receiving side does not have a mail queue )

  • Configurations include access control lists, content scanning, encryption, routing controls among others

  • Excellent documentation

  • It has utilities such as Lemonade which is an assortment of SMTP and IMAP extensions to enable mobile messaging plus many more.

3.Qmail

Qmail is also another free, open-source and modern Linux MTA when compared to the other MTAs we have looked at. More over, it is simple, reliable, efficient and offers extensive security features hence a secure MTA package.

It is relatively small but feature-rich and some of its features include:

  • Runs on multiple Unix-like operating systems such as FreeBSD, Solaris, Mac OSX plus many more

  • Simple and quick installation

  • Automatic per-host configuration

  • Clear separation between addresses, files and programs

  • Full support for address groups

  • Lets each user manage their own mail lists

  • Supports an easy way to set up mailing list

  • Supports VERPs (variable envelope return path addresses on request) undeliverable mail can reveal the undeliverable recipient address without requiring the list owner to parse bounce messages.

  • Supports automatic prevention of mailing list loops

  • Supports ezmlm mailing list manager

  • No random lists supported and many more

4.Postfix

Postfix is a cross-platform, popular MTA that was designed and developed by Wietse Zweitze Venema for his mail server while working at IBM research department.

It was primarily developed as an alternative to well known and popularSendmail MTA. Postfix runs on Linux, Mac OSX, Solaris and several other Unix-like operating systems.

It borrows a lot of Sendmail properties on the outside, but it has a totally and comprehensively distinct internal operation. Additionally, it bids to be fast in performance with easy configurations and secure operation mechanism and has the following major features:

  • Junk mail control

  • Supports multiple protocols

  • Database support

  • Mailbox support

  • Address manipulation support and many more

For LPIC2 exam we are just expected to know about Postfix and its configuration files, so just know about other MTAs existance.

Postfix Configuration

Lets Install post fix and mail ustils (We will use CentOS7):

as Postfix in our distrobution is used as local mail delivary service it is already installed.

/etc/postfix

Lets see configurations to find out how its configured.

main.cf

The Postfix main configuration file is main.cf (please note that there is a master.cf also). The main.cf file has tones of Documentations and settiing are in key value pairs (Something = Value). try cat main.cf to see.

To see just customized settings in post fix configuration we use postconf -n command:

And if we use postconf without -n then it shows all settings ,even defaults. So if we have made some changes we would use "-n" switches to do more investigation on that.

Lets take a look at most impotant setting of postfix in main.cf file:

myhostname : By default specifies the internet name host name of this mail system, For none public Postfix mail servers(Like what we have here ) by defualt it usesget hostname if it is not set! How ever if we are going to have a publicly available email server or even internally , as long as we have a DNS entry for our Server, we should certainly set what our hostname is with Full Domain:

One of the benefits of setting myhostname and mydomain is that from now on we can easily reffer to it using $myhostname during configuratoin.

mydomain : Set domain name for our email server, The default is to use $myhostname minus the first component:

disable-vrfy-command (might not exist in configurations) It avoid e-mail address mining by doing some things behinde the scenes, that make scanning for e-mail addresses more deficault for thoese systems which are designed to do exactly that. if we are going to configure a publicly available mail server then we should set it to "yes". The default value, even if dose not exist, is "no",( no matter where we put that in configuration file):

inet_interfaces it determines what interfaces on our server that the postfix process will listen for connections on. by default it is set for "only local host"

But for configuring an internl mail server which provides connectivity for other clients, or if we are going to offer connectivity for internal and external clients, we should set it to "all":

mydestination it is set to "myhostname" by default, and it is a list of all the domain or the systems and host that the postfix accept e-mail for. If we had a plan for accepting e-mails from other domains, or aggregate multiple domains then would list the appropriate host and domains here "," delimited and postfix would accpet mail from each of those domains.

We should also make sure that if we are accepting mail from domains outside of localhost, then we should have mx records for our mail server in our DNS, because many mail servers won't deliver e-mail to the host which dosen't have appropriate mx record for the host that is the authorative responsibilty for a paricular doman.

relay-domains : it canhave multiple values that depends on what we are going to allow ourself to e-mail relay for, we can use $mydestination which previously defined or we ca use full host and domain name that we are going to accept e-mail and then relay e-mail to another domain:

relayhost : defines the next connection that we have for SMTP:

These were settings that we need to know at minimum to setup our postfix configuration for a local host based distribution system for SMTP email.Lets go a head. Unfortunately there isn't any tools for configuration test so we use ordinary things:

sendmail emulation layer commands

As we said Sendmail is the oldest MTA, thus any other MTA which has come after SendMail, has tried to keep itself backward compatible with sendmail by providing a sendmail emulation layer. So we can use sendmail commands on the command line regardless of what MTA has been installed in our distrobiution. Two examples of that are mailqand sendmail. mailq is available on most systems to check the mail queue. It is equivalent to sendmail -bp, which works with Postfix too.

mail command

Lets send a local e-mail from one user to another:

some of mail command hot keys are:

/var/spool/postfix

In this directory postfix does its stuf. Any queued messagesare stored here:

You can see large number of directories here. Most of these directories will only have information if postfix configuration is holding e-mail for some reason or if it is waiting to deliver it, otherwise most of these directories(except pid or corrupt) should always remain empty.

/var/spool/mail

Specifies the default mail drop directory. By default all mail is delivered to the /var/spool/mail/<username> file.

when postfix recieve a message, if its going localy then it goes to /var/spool/mail directory on the local system, if it is going to be send it some where else , ( it will exist in /var/spool/postfix directory long enough to send the e-mail out and then it wiil flush and clear the directory once it has been successfully sent.

Logging

Postfix uses the syslog daemon for its logging. When/etc/syslog.confis configured.Lets take a closer look at look at postfix activities :

email aliases

email aliases are desgined for e-mail system to take an e-mail that is for one destination address, and then send it to a different one. Literally an alias for different name.

/etc/aliases

Used to redirect mail for local recepients.

Each line of /etc/aliases has the format of alias: user. Two system aliases must always be present: mailer_daemon: postmaster and postmaster: root. We can use aliases for all kind of daemons, for example use ntp: root. Now we can add a line to redirect all mail to root to a specific user or group of administrators, for example user3: root. So although we dont have any "user3" in our system, but if an e-mail is sent to user3 it would not be rejected.

newaliases

After any changes in /etc/aliases we need to re-create binary file aliases.db . For that we stop postfix service, use newaliases command to re-create aliases.db and then start the postfix service again:

Now lets send an e-mail to user3:

virtual

virtual is similar to aliases but it is used to redirect e-mail to the virtual destinations. It is common in multiple domain e-mail implementations. Like aliases we provied a list of an e-mail address that goes to something else.

In our case as we are not doing any relays, we are not configuring for any domains, there is nothing for us to really test here, other than being aware of this particular setting allow us to control e-mail for other domains especially in a multi domain systems or seperate servers.

For demonstration we just show how it would be:

Try cat /etc/postfix/virtual . It has all kinds of rules that we can apply .

For example we can add these two items at the bottom of /etc/postfix/virtual file(stop postfix service before that):

Like aliases we would need to convert it to binary files using postmap command:

Next we need to set aliasvirtualmaps in main.cf configuration file:

and do not forget to start postfix service . try tail /var/log/maillog to find out what is going on after setting up virtuals.

That was some of most important postfix files and configurations!

Last updated