If you have installed and configured both sendmail and Postfix, be careful. Don't activate both. There are two simple commands that can help you select the default e-mail server: alternatives and system-switch-mail.
Once you select a system, you need to know how to test the system. Sure, you can set up Thunderbird or Evolution, but that takes time. It's easiest to use the mail utility to send a quick e-mail. When you do so from a remote system, you can make sure the active server does what you want, and does not accept mail from other systems.
The alternatives command is straightforward. Try the following:
# alternatives --config mta
You'll see this output, which allows you to choose from installed e-mail servers:
There are 2 programs which provide 'mta'. Selection Command ----------------------------------------------- *+ 1 /usr/sbin/sendmail.sendmail 2 /usr/sbin/sendmail.postfix Enter to keep the current selection[+], or type selection number:
When you select sendmail or Postfix, alternatives changes the appropriate runlevel scripts, which you can confirm with the following commands:
# chkconfig --list sendmail # chkconfig --list postfix
For example, if you've previously activated Postfix and select sendmail, alternatives stops Postfix and starts sendmail. However, if neither service is started, you'll have to do it yourself with one of the following commands:
# service sendmail on # service postfix on
Don't activate both sendmail and Postfix on the same system.
If you can't remember how to use alternatives, you can use the system-switch-mail command. If you use it, it opens a simple console tool, as shown in Figure 12-1. As you can see, all you need to do is use your keyboard to select between installed e-mail servers.
Figure 12-1: system-switch-mail
The disadvantage of system-switch-mail is that it's not installed by default; you may have to install the system-switch-mail RPM to use the associated command.
One of the prerequisite skills for the Red Hat exams is to configure an e-mail client. This should be easy for anyone who has used Linux for any length of time. In fact, the process for graphical Linux clients such as Evolution or Thunderbird is quite similar to the process for various Microsoft e-mail clients. But as you've seen earlier in this section, there are text-based mail clients as well.
To test your mail system, you can use the built-in command line mail utility, a simple text-based interface. The system keeps each user's mail in a system directory. Once users read a message, they can reply, forward, or delete it. If they do not delete the message before quitting the mail utility, the system stores the message in the /var/ mail directory in a file named after the applicable username.
You can certainly use any of the other mail readers, such as mutt or the e-mail managers associated with different GUI Web browsers, to test your system. Other mail readers store messages in different directories. For example, pine would create and store messages for user mj in the /home/mj/mail directory.
To send mail to another user, you can use the mail command line utility. There are two basic methods for using mail. First, you can enter the subject and then the text of your message. When you're done, press CTRL-D and then enter another addressee in the Cc: line, if desired. When you press ENTER, the message is sent and the mail utility stops and sends you back to the command line.
$ mail Michael Subject: Test Message Sent and received Cc: mjang@example.com $
But even that takes time. Alternatively, you can redirect a file as the text of an e-mail to another user. For example, the following command sends a copy of /etc/hosts to the root user, with the subject name of hosts file:
$ mail root@enterprise5a.example.net -s "hosts file" < /etc/hosts
Here's one more example, which sends an e-mail containing the words test message under a subject name of test subject.
$ echo "test message" | mail -s "test subject" root@enterprise5a.example.net
You may want to test mail servers with a simple command line client such as mail. It's certainly faster than configuring a client such as mutt or Evolution.
By default, the mail system doesn't open unless you actually have e-mail in your inbox. Once the mail system is open, you'll see a list of new and already read messages. To read a specific message, enter the number of the message and press ENTER. If you press ENTER with no argument, the mail utility assumes you want to read the next unread message. To delete a mail message, use the d command after reading the message, or use d# to delete the message numbered #.
If you have a distribution list of people for the same e-mail, you can set it up in the /etc/aliases file. By default, it's set up to forward e-mail from pseudo-accounts such as system and apache to root. You can change it by adding a group list similar to the following:
groupname: user01, user02, othergroupname
Alternatively, you can forward e-mail from one employee to another. For example, you can add the following line to forward e-mail from oldemployee@yourdomain.abc to newemployee@yourdomain.abc:
oldemployee: newemployee
You can then run the newaliases command to compile this database. Then all you need to do is name the group of users as addressees for your e-mail.
If you have to install an e-mail server during the RHCE exam, you'll want to be able to test the results. You could configure familiar GUI e-mail clients, but that takes time. The easiest method uses the mail command, which is part of the default mailx package. Once you've configured sendmail or Postfix and Dovecot to run on your system, you can try it out at least from the local computer.
Exercise 12-1: Testing E-mail Services
If you haven't started an e-mail server such as sendmail or Postfix, this exercise won't work. If necessary, configure one of these servers as described earlier in this chapter. This exercise also assumes you have a working DNS server. If you do not, make sure you configure host names and IP addresses in /etc/hosts.
Activate the Dovecot service on the local computer. If you haven't already done so, configure it as described earlier in this chapter.
If you have problems activating Dovecot, make sure SELinux protection for this service is disabled.
Open /etc/aliases, and have e-mail forwarded from one user to another. For the purpose of this exercise, I have e-mail forwarded from user nancy to user michael. User nancy does not have an account on my system. I've added the following entry to /etc/aliases:
nancy: michael
Run the newaliases command to process the alias.
Inspect the result in /var/log/maillog. What do you see?
Go to another system. It's acceptable to do so with a remote service such as SSH (described in Chapter 13).
Send an e-mail to the user on your original system. In my case, I'm sending it to user nancy.
Check the result in the mail spool and log files. If everything works, you'll see the message in /var/spool/mail/michael (substitute your target username for michael). You'll also see a message in the remote system's (the computer from where you sent the e-mail) /var/log/maillog file. If there's a problem, you'll see a message in /var/log/maillog similar to this:
connection refused by: