Managing email

Linux follows Unix method of handling email. The main feature of Unix operating systems regarding mail is that email processing software is modular. Instead of having one program that handles all pieces required for sending and receiving mail, Linux uses small programs that work together. The Linux modular environment consists of following pieces:

  1. Mail Transfer Agent (MTA) – sends incoming mails to MDA or local user’s inbox.
  2. Mail Delivery Agent (MDA) – program that delivers messages to local user’s inbox.
  3. Mail User Agent (MUA) – it is graphical interface for users to read their mail. MUA do not receive messages, they just display messages that are already in user’s mailbox.

Choosing email software

  • Sendmail – Sendmail MTA program was most popular Linux MTA program due to its versatility. It had features such as message forwarding, user aliases, mail lists. But, with versatility comes complexity, therefore it had large configuration file which was overwhelming for new administrators to handle.
  • Postfix – Postfix was written as modular program meaning it had several different programs to implement MTA functionality. Best feature was simplicity and it enhanced security over MTA products like Sendmail. Nowadays, Postfix is popular email software.
  • Exim – Best feature of Exim is flexibility. It is available in most Linux repositories and comes with reasonable default configuration.

Working with Email

It is important to know how to use MDA software. The binmail program was the most popular MDA program on Linux systems. The name binmail comes from its location on the system /bin/mail. The binmail program became popular because of its simplicity.

By default, binmail reads email messages from /var/spool/mail/ directory. To install binmail on your Debian system install bsd-mailx and for CentOS install mailx package.

The recipient can be either a username on the same system, or a fully qualified domain.

# mail -s "This is email subject" aldin

These are flags for mail command:

  • -s subject : line for the mail
  • -cc recipient : recipient receives copy of the email. All email recipients can see this address
  • -bc recipient : recipients receive copy of the email. However, only the sender can see this address
  • -v : displays delivery details for the email message

To read your emails, type mail. You can read other users’ mails if you have right permissions. To do that, use -f flag.

Checking the email queue

All mails that did not go through meaning they were not sent, are stacked inside mail queue. There are two commands to view mail queue: mailq and sendmail -bp

If there is nothing inside mail queue, that means that all mails have been sent. The mail queue is typically located inside /var/spool/ directory.

Redirecting email

Instead of sending mail to the recipient using his email address, you can set an alias for that email. This is great feature because it does not let any malicious attacker to see the real email address of the recipient. There are two steps to set up an email alias:

  1. Add the alias to the /etc/aliases file
  2. Run the newaliases command to update the aliases database (/etc/aliases.db)

So, if you set an alias like this:

master: root

… if you send email to master, it will be eventually sent to the root user. This is the example of setting up a new alias and sending email to that recipient:

# cat /etc/aliases
master: aldin bob
# newaliases
# mail -s "This is a mail sent to aldin and bob" master

Now, we have sent email to the aldin and bob users on the system. Another feature you can do is forwarding email. Two steps must be done:

  1. User creates .forward file in their home directory. User puts in username who should be receiving that forwarded email.
  2. Use chmod command for .forward file and set permissions to 644.

Now, if user aldin has .forward file inside his home directory, whichever username is inside that file, all mail sent to user aldin is redirected to username that is inside .forward file. Simple enough. To stop forwarding, user aldin removes .forward file from his home directory.

Leave a Reply