Colorado State University

Basic UNIX Electronic Mail Commands



What is Electronic mail (email)?

Electronic mail (E-mail, Email, e-mail, or email) on a Unix system is invoked with the mail or mailx command. We recommend you to use the Unix mailx utility if at all possible.


Sending Mail

Invoking Mail To Send Messages

To invoke the UNIX mail utility program to send messages, type

            mailx email-names

or

            mailx -s subject email-names

where email-names is a list of electronic mail names of people to whom you wish to send the message and subject is the subject (or title) of the message being sent. The email name may be as simple as name or name@machine or may require the name followed by a fully qualified host/domain name (e.g. name@CS.ColoState.Edu). If the mailx command does not prompt you for a subject (which is nice to include for the receiver of the mail), it can be included with the -s option.

After invoking the mailx utility, simply type in lines of text (hit the <Return> key after entering each text line). When you are done entering the message, hit <Ctrl>-D (at the start of a new line) to send the message (and exit back to the system or UNIX prompt). To abort a message and exit mailx, type <Ctrl>-C twice.

Message Text Commands

Tilde escapes are entered at the start of a text line (when entering mail message text) to perform some useful operations. Hit the <Return> key after entering a tilde escape sequence/command.

~? to list all tilde (~ ) escapes (i.e. a help display)
~p to list the text of the message typed in so far
~s subj to set or change the current subject field to subj
~t enams to add the enams list of email names to the current list of email-names
~h to list and to modify the subject and/or the email-names list
~! cmd to execute the UNIX command cmd from within mailx utility
~r fname to read the file fname into the message at current position
~v to invoke the vi editor on the message text to edit it
~q to exit mailx, and
to save the current message in the file named dead.letter in your home directory


Receiving Mail

Invoking Mail To Receive Messages

To invoke the UNIX mail utility program to receive messages, type

            mailx

A response "No mail for user_name" means there are no new or old saved mail messages. Entering the utility means you have mail (when you log in the system informs you if you have mail).

The following commands may be used within mailx:

h to list the headers of the mail messages in your mailbox
<Return> to continue the current or display (print) the next mail message in your mailbox
+ or n to display (print) the next mail message in your mailbox
- or z to display (print) the previous mail message in your mailbox
# to display (print) the message numbered # in your mailbox
t MSGS to display (print) the messages indicated by the message range MSGS
d MSGS to delete the messages indicated by the message range MSGS
s MSGS fname to saved the messages indicated by the message range MSGS to the file named fname
R msg to reply (and send mail) to the authors of the message msg
r msg to reply (and send mail) to all the recipients of the message msg
m name to send mail message to person named name and enter current message text
top MSGS to list the top 5 lines of each message indicated by the message range MSGS
q to quit and preserve all unread messages in your mailbox
x to quit and preserve all messages in your mailbox

Notes on Above Table of Commands:

  1. MSGS specifies messages by number, author, subject or type. The default is the current message.

  2. A range of MSGS by number is of the form, for example, of 2 3 4 or of 2-4 (meaning the messages numbered 2 through 4).

  3. msg is the number of a message and defaults to the current message.


Notes, Warnings and Other Information about E-Mail

E-Mail Advantages/Disadvantages and To Whom You Can Send E-Mail

Electronic mail is a good way to communicate directly with another person since you can relay information to them without having to talk to them directly. However, written text cannot always substitute for direct verbal communication. Electronic mail is also self-documenting and can be used to transmit all kinds of information (i.e. personal notes, memos, documents etc.).

A big problem with e-mail is that the receiver may not examine their mailbox often and regularly (i.e. all is for naught). Thus, take heed.

You may send mail to virtually anyone anywhere with the proviso that the person has a computer account, a mail system, and is tied to some network. The main problem for sending mail to someone is that there is (currently) no grand directory of everyone everywhere. Thus it is sometimes necessary to call (via phone) someone to get their address for e-mailing.

The .mailrc File

This is a file located in your login directory (create or modify it with vi) that contains tuning/tailoring commands for mailx which is read every time you invoke mailx. Some useful commands (one per file line) are given in the following table.

set ask to force prompting for a subject for each message you send
set asksub to force prompting for a list of carbon copy recipients of any messages sent
set askcc to enable paged listings of long messages you list/read
alias new old to reference old whenever you type new;
  e.g. if .mailrc contains alias horton hearsawho@where,
      then mailx horton sends mail to hearsawho@where.
alias A B C D to reference a single group name (A)
  when you want to send mail to all the members of that group
      (B, C, and D)
;
  i.e. a convenient way to send a message several people

The .forward File

This is a file located in your login directory (create or modify it with vi) that contains forwarding information about where any mail message that is sent to you at this account on this machine is to be forwarded. If the .forward file does not exist, then the mail message is put in your mailbox on this account on this machine. If the file does exist, then the mail is forwarded to wherever the name@domain line in the .forward file indicates it should be sent. No copy of the message will be put into the mailbox on the account on the machine before it is forwarded.

Warning: Be careful of creating a forwarding loop. That is, do not have mailboxes that forward to each other and do not have a string of forwardings that forwards back upon itself. Please be careful about this.

Other Mailboxes

If you have a mailbox elsewhere, you may wish to forward all class related material/messages to it. On the other hand, you may wish to keep the class material/messages separate and thus have no forwarding from your class account. However, in the latter case, you now have two mailboxes that you must examine often and regularly.


E-Mail Etiquette

When you send email to someone, you are addressing another person directly as if you were calling them on the phone or writing them a letter. Thus the following should always be done when sending email:

  1. Always include a short subject field in your mail message

  2. Always include a salutation to the person to whom you are writing (i.e. Hi Joe, or Dear Frank, or Sue, or Dear Mx. Yin, etc.)

  3. Always nicely space the text of your message

  4. Never type more than about 70 characters per line of message text before hitting a return

  5. Always sign your name after the text of your email message

  6. Always include relevant information after your name (phone number, email address, postal address, organization, etc.)
    This information would depend on how well you know the person, or what they might need to know to contact you, etc.

  7. BEFORE you send your message, read over your message, correct spelling and/or grammar, and make sure that your message
    1. clearly specifies what you are talking about and
    2. provides all necessary information that the person will need in order to sensibly respond to you



Comments: