What I Mean
What I mean is for one user to be able to send a message to another user or to root or vice versa all within the local system.
I don't really need to do that though. What I need is for certain applications that can email warnings to be able to send those messages to me on the local machine. That also can be handy for scripts that need to notify somebody that something happened. For example, a test message from the Smartmontools smartd daemon to root (aliased to a non-root user)...
For people who already have a mail MTA and MUA installed, this will not be interesting because they can already do this. I didn't. And I promise you that the information about this on the Internet is not easy to piece together. I looked through stuff for a long time until I found something helpful and learned how to do this. Most information out there is about sending to and receiving from remote machines. I only want to work with this within a system.
Anyway, all you have to do is install two simple packages that happen to be in the current BLFS book. One is an MTA (mail transport agent) and the other is an MUA (mail user agent). I tried several different ones and finally ended up with Mailx for the MUA and Postfix for the MTA. That part was easy, but it didn't work at first. Then it worked for a minute and went away, but I didn't know what I did to make it work or stop working. Finally, I got it all figured out and can reproduce the whole thing reliably. It's mostly about getting the configuration files right. Mostly.
Installing Postfix and Mailx
1. Install Postfix.
The current version is postfix-2.9.4 and can be found in chapter 21. I merely did the basic steps in the book for installing Postfix with OpenSSL. No problems.
2. Create /etc/aliases.
This is one of the steps in "Configuration Information" in the book for Postfix. Again, I did the cat
command in the book and changed <LOGIN>
to my regular non-root user.
3. Edit /etc/postfix/main.cf.
This is more from the configuration of Postfix, but the book is stingy with details for this part. Open the default main.cf file created by Postfix and uncomment or change the following items. My hostname is the venerable localhost.localdomain. Change that as needed for yours in the following...
myhostname = localhost4. Finish and test the configuration.
mydomain = localdomain
myorigin = $myhostname
inet_interfaces = $myhostname, localhost
mydestination = $myhostname, localhost.$mydomain, localhost
mynetworks_style = host
And add this at the end if you want to keep things local...
# The following setting disables the delivery of non-local mail.
default_transport = error:outside mail is not deliverable
The following commands will run without returning any messages if everything is okay so far.
postfix upgrade-configuration5. Rebuild the data base
for the mail aliases file.
newaliases6. Install the postfix init script
as described in the book. This will start the Postfix mail daemon automatically at boot time.
7. Reboot or run the init script
to start the postfix daemon.
/etc/rc.d/init.d/postfix start8. Install Mailx.
The current version in the book is mailx-12.4 and can be found in chapter 19. I installed Mailx exactly as described in the book with the patch for OpenSSL. I did nothing to its default configuration file /etc/nail.rc.
There is plenty of documentation available for learning to use Mailx. Here are some very basic things. The commands mail
both are symlinks to the executable mailx.
Check your mail messages...
Heirloom mailx version 12.4 7/29/08. Type ? for help.
"/var/mail/boo": 3 messages
>O 1 Jean Finch Mon Oct 29 21:05 20/641 WARNING!
O 2 Jean Finch Mon Oct 29 21:08 20/646 False Alarm!
O 3 Arthur Radley Mon Oct 29 21:49 25/878 Re: False Alarm!
Send mail to address
The ? prompt
$ mail boo
Subject: This is an important message
How am I doing?
When the mail command lists the mail in the user's mailbox, it ends by printing a ? prompt for commands. Here are some things to do at the ? prompt.
d, delete [msglist]Send messages via the command line or from a script.
d Delete the current message.
d3 Delete the third message.
d1-3 Delete messages 1 to 3.
Reply to the sender and all other recipients of the original message.
Reply only to the sender, not other recipients.
h Show the list of message headers (or the first 18 in a long list).
h+ Show the next 18 headers in a long list.
h- Show the previous 18 headers in a long list.
Print a brief summary of commands.
Terminate the session saving all undeleted and unsaved messages.
x, ex, exit
Return immediately to the shell without modifying the user's system mailbox.
echo "Something really important happened." >> message_file.txt
echo "Somebody should do something about this." >> message_file.txt
mail -s "Some interesting stuff" email@example.com < message_file.txt
See the many Mailx references and tutorials out there for much more Mailx information.