Linux Exercise: Mail Transfer Agent (MTA) Basics
Installing the MTA and MUA
On a CentOS/Red Hat 8 or newer system, there may not be any mail components installed. If that's the case, you will need to install these.
Install Sendmail and Mailx. Make sure the Sendmail daemon is enabled and running.
Note that on Red Hat / CentOS 9 or higher, the mail and mailx commands are now implemented using a program called s-nail.- # yum -y install sendmail
- RH7-8: # yum -y install mailx
- RH9+: # yum -y install s-nail
- # systemctl start sendmail
- # systemctl enable sendmail
- # systemctl status sendmail
Sending mail
Login as tux1. Send an e-mail to tux2.
- tux1$ mail tux2
- Subject: bla
- test
- .
Login as tux2. Check your e-mail.
- tux2$ mail
- tux2$ ha
- tux2$ t 1
- tux2$ q
Mail forwarding
Change the /etc/aliases file so that all mail for root, is now forwarded to tux1. Make sure the aliases are active.
- # vi /etc/aliases
Add the following to the end of the file:root: tux1
- # newaliases
- # vi /etc/aliases
As tux2, send an e-mail to root. Where does this end up?
- tux2$ mail root
- ...
- tux1 mail
- ...
As the user tux1, make sure all your e-mail is forwarded to tux2. Use a .forward file for this. Make sure the .forward file has permissions 644 otherwise it will not work.
- tux1$ vi ~/.forward
tux2
- tux1$ chmod 644 ~/.forward
- tux1$ vi ~/.forward
As tux2, send an e-mail to tux1. Where does this end up?
- tux2$ mail tux1
- tux2$ mail
Mail Queues
Use the mail command to send something to your own e-mail address.
- tux2$ mail me@gmail.com
- ...
Because the system is not configured for outgoing mail, this message will remain in the queue. Look at the mail queue.
- # mailq
Also check out the logfile of the mail system, to see why the message was not forwarded.
- # tail /var/log/maillog
It may take a few minutes before messages start appearing.
- # tail /var/log/maillog