Using Text Based Email Clients

Most Mail User Agents (MUAs) are GUI-based these days. So if you began using e-mail in the past decade or so, you probably think of Evolution, Kmail, Thunderbird, or (on Windows systems) Outlook when it comes to e-mail clients. On the first Unix and Linux systems, however, e-mail was handled by text-based applications.

If you find yourself needing to check e-mail on a remote server or other text-based environment, venerable text-based mail clients are available and still quite useful. In fact, some hard-core geeks still use text-based mail clients exclusively, touting their efficiency and scoffing at HTML-based messages.

The mail clients described in this chapter expect your messages to be stored in standard MBOX format on the local system. That means that you are either logged into the mail server or you have already downloaded the messages locally (for example, by using POP3 or similar).

NOTE Text-based mail clients can be used to read mail already downloaded by other mail clients. For example, you could open your Evolution mail Inbox file by typing mail -f $HOME/.evolution/mail/loc/Inbox.

Managing E-mail with mail

The oldest command, and easiest to use when you just want a quick check for messages in the root user's mailbox on a remote server, is the mail command (/bin/mail). Although mail can be used interactively, it is often used for sending script-based e-mails. Here are some examples:

$ mail -s 'My Fedora version1 [email protected] < /etc/redhat-release $ ps auwx | mail -s 'My Process List1 [email protected]

The two mail examples just shown provide quick ways to mail off some text without having to open a GUI mail application. The first example sends the contents of the

/etc/redhat-release file to the user [email protected]. The subject (-s) is set to 'My Fedora Version'. In the second example, a list of currently running processes (ps auwx) is sent to the same user with a subject of 'My Process List'.

Used interactively, by default the mail command opens the mailbox set by your current shell's $MAIL value. For example:

/var/spool/mail/root

Mail version 8.1 6/6/93. Type ? for help, "/var/spool/mail/root": 25 messages 25 new

/var/spool/mail/root

Mail version 8.1 6/6/93. Type ? for help, "/var/spool/mail/root": 25 messages 25 new

>U

1

[email protected]

l

Fri

Jun

15

20

03

44/1667

"Logwatch

for

ab

(Linux)

U

2

[email protected]

l

Sat

Jun

16

04

32

87/2526

"Logwatch

for

ab

(Linux)

3

[email protected]

l

Sun

Jun

17

04

32

92 /2 693

"Logwatch

for

ab

(Linux)

N

4

[email protected]

l

Fri

Jun

22

09

28

44/1667

"Logwatch

for

ab

(Linux)

N 5 [email protected] Fri Jun 22 09:28 93/3348 "Warning: could not send "

N 5 [email protected] Fri Jun 22 09:28 93/3348 "Warning: could not send "

The current message has a greater-than sign (>) next to it. New messages have an N at the beginning, unread (but not new) messages have a U, and if there is no letter, the message has been read. The prompt at the bottom (&) is ready to accept commands.

At this point, you are in command mode. You can use simple commands to move around and perform basic mail functions in mail. Type ? to see a list of commands, or type the number of the message you want to see. Type v3 to open the third message in the vi editor. Type h18 to see a list of message headers that begins with message 18. To reply to message 7, type r7 (type your message, then put a dot on a line by itself to send the message). Type d4 to delete the fourth message (or d4-9 to delete messages 4 through 9). Type !bash to escape to the shell (then exit to return to mail).

Before you exit mail, know that any messages you view will be copied from your mailbox file to your $HOME/mbox file when you exit, unless you preserve them (pre*). To have all messages stay in your mailbox, exit by typing x. To save your changes to the mailbox, type q to exit.

You can open any file that is in MBOX format when you use mail. For example, if you are logged in as root user, but want to open the mailbox for the user chris, type this:

# mail -f /var/spool/mail/chris

Managing E-mail with mutt

If you want to use a command-line mail client on an ongoing basis, we recommend you use mutt instead of mail. The mail command has many limitations, such as not being able to send attachments without encoding them in advance (such as with the uuencode command), while mutt has many features for handling modern e-mail needs. The mutt command is part of the mutt package.

Like mail, mutt can also be used to pop off a message from a script. mutt also adds the capability to send attachments. For example:

$ mutt -s "My Fedora Version" -a /etc/redhat-release \

[email protected] < email-body.txt $ mutt -s "My Fedora Version" -a /etc/redhat-release \ [email protected] < /dev/null

The first example just shown includes the file email-body.txt as the body of the message and attaches the file /etc/redhat-release as an attachment. The second example sends the attachment, but has a blank message body (< /dev/null).

You can begin your mutt mail session (assuming your default mailbox is $MAIL) by simply typing mutt:

$ mutt

/home/chris/Mail does not exist.

. Create it? ([yes]/no): y

q:Quit

d:Del u:Undel s:Save

m:Mail r:Reply

g:Group ?:Help

1 O

Jun 16 [email protected]

( 69) Logwatch

for ab (Linux)

2 O

Jun 18 [email protected]

( 171) Logwatch

for ab (Linux)

3 O

Jun 18 Mail Delivery S

( 219) Warning:

could not send message

4 O

Jun 19 [email protected]

( 33) Logwatch

for ab (Linux)

--Mutt:

/var/spool/mail/root [Msgs:22 New:2 Old:

:2 0 63K]--(date/date)--(all)-

Because mutt is screen-oriented, it is easier to use than mail. As with mail, you use key commands to move around in mutt. As usual, type ? to get help. Hints appear across the top bar to help you with your mail. Use the up and down arrow keys to highlight the messages you want to read. Press Enter to view the highlighted message. Use PageUp and PageDown to page through each message. Press i to return to the message headers.

Search forward for text using slash (/) or backwards using Escape slash (Esc-/). Type n to search again. Press Tab to jump to the next new or unread message. Or go to the previous one using Esc-Tab. Type s to save the current message to a file. Type d to delete a message and u to undelete it.

To send a new mail message, type m. After adding the recipient and subject, a blank message opens in vi (or whatever you have your $EDITOR set to). After exiting the message body, type a to add an attachment, if you like. Type ? to see other ways of manipulating your message, headers or attachments. Press y to send the message or q to abort the send.

When you are done, type x to exit without changing your mailbox; type q to exit and incorporate the changes you made (messages read, deleted, and so on).

Computer Hard Drive Data Recovery

Computer Hard Drive Data Recovery

Learn How To Recover Your Hard Drive Data After A Computer Failure.

Get My Free Ebook


Post a comment