The use of the Mail command under the Linux system

Source: Internet
Author: User
Tags aliases

Test of the Mail command under the Linux system

1. One of the simplest examples:

Mail-s test [email protected]r.com

The result of this command is to send an empty letter titled Test to the back of the mailbox, if you have an MTA and the back of the mailbox will not block this potentially inexplicable letter, you can receive this letter. If you don't want to be distracted by this mess, use your local account in the back of the mailbox.

2. A second example:

Three commonly used formats for sending letters

Mail-s test [email protected]r.com #第一种方法, you can use the current shell as an editor, finish editing the content ctrl-d end

echo "Mail Content" |mail-s test [email protected]r.com #第二种方法, I used the most, probably like plumbing sake

Mail-s test [email protected]r.com< file #第三种方法, the content of file is within the message. Letter of tolerance

Mail-s test [email protected]r.com < file #第三种方法, send mail content as file

Mail-s test-c [email protected]r.com [email protected]r.com< file #第四种方法, send mail to multiple users

3. Third example, mail with attachments

If you do not have a uuencode command in your system, please install Sharutils (yum install-y sharutils) first.

Uuencode need two parameters, the first is the file you want to send (we), of course, this can also be done with a pipeline, the second is the display of the filename

Uuencode/home/yfang/a.gif a.gif|mail-s pictest [email protected]r.com

Tar Czf-/home/yfang/| Uuencode home.tgz |mail-s pictest [email protected]r.com

PS: By the way, Slackware Mail seems to have a-a parameter, you can add attachments directly, I have not used.

4. Read the Mail

The Mail command collection system received by Linux will be saved in the "/var/spool/mail/[linux User name" file.
When you enter mail in Linux, you have your Inbox and display a list of 20 messages.

& Help//If you don't use or forget any commands, enter Help or? To get help
Mail Commands
T <message list> print out the message "note" Multiple information is separated by a space, such as T 1 7
n Print out the next piece of information
E <message list> Edit information
F <message list> the header line of the output information
D <message list> Delete information
s <message list> file append information to files
U <message list> do not delete a message
R <message list> Reply to Sender
R <message list> reply to sender and all recipients of this information
Pre <message list> reserved information in/usr/spool/mail 1*
M <user list> e-mail, multiple recipients separated by a space "need sendmail support"
Q quit, saving unresolved messages in mbox
x quit, do not remove system mailbox
H Print out active message headers
! Let the shell execute a command, such as!ls output ls command result
CD [Directory] Change directory, there is no!CD, but print the current directory needs!pwd
A <message list> consists of integers, ranges of same, or user names separated
by spaces. If omitted, Mail uses the last message typed.
A <user list> consists of user names or aliases separated by spaces.
Aliases is defined in. MAILRC in your home directory.


1* If you read a message, when you perform Q exit, Mail will "get back" the information you have read and put it in the ~/mbox, and do not retrieve it after the pre-execution. If the Execute x command exits, the information is not retrieved.
The three sentences are not difficult to understand, but not good translation (I level problem), also retained the original

List of all supported commands:
& L
Commands is:
Next, alias, print, type, type, print, visual, top, touch, preserve,
Delete, DP, DT, undelete, unset, mail, mbox, more, page, more, page,
Unread, U,!, copy, ChDir, CD, save, source, set, Shell, version,
Group, write, from, file, folder, folders,?, Z, headers, help, =,
Reply, Respond, Reply, Respond, edit, Echo, quit, List, XIT, exit,
Size, hold, if, else, endif, alternates, ignore, discard, retain,
Saveignore, Savediscard, Saveretain, Core, #, clobber

& T 7//Read the 7th message, when reading, press the SPACEBAR is the page, press ENTER to move down one line
& D 10//delete 10th message
& D 10-100//delete 第10-100 message
& Top//Displays the message header of the message that contains the current pointer
& File//Display system e-mail files, and the total number of messages and other information
& X//exit the Mail command platform and do not save previous operations, such as deleting messages
& Q//exit the Mail command platform to save previous operations, such as deleting messages that have been deleted with D,
Messages that have been read are transferred to the Mbox file in the current user's home directory
Deleting a file in mbox is completely removed.
--------------------------------------
Linux Mail command usage

1. Send the file as e-mail content
Syntax: mail-s "subject" User name @ Address < file
For example:
Mail-s "program" User < file.c will file.c

As the content of mail, send to user, subject to program.

2. Send email to users of the system
Syntax: Mail user name

3. Send email to a foreign user
Syntax: Mail user name @ Accept Address
.../usr/lib/sendmail-bp
..... "Mail queue is empty" ... mail .....

For example:
[Email protected]
Subject:mail Test
:
Type the content of the message
: :
Press the Ctrl+d key or. Key to end the body.
Press the CTRL + C key two times to interrupt work and not send this letter.
Cc (Carbon copy): Copies a copy of the text to other addressee.

4. Check whether the sent email is delivered or stuck in the mail server
Syntax:/USR/LIB/SENDMAIL-BP
If the screen appears as "Mail queue is empty" information, it indicates that Mail has been sent out.
For other error messages, the email has not been sent for any reason.

=================================

mail, mail, or MAILX commands

Use

Send and receive messages.
Grammar
Read a new message

Mail-e

mail-f [-DHNN] [-f] [FileName]

mail [-DHNN] [-f] [-u UserID]
Send mail

Mail [-S Subject] [-C Address (es)] [-DINNV] Address
Describe

The Mail command invokes the message utility, enabling you to:

* Read the new message.
* Send mail.

In addition, you can use the available options and subcommands to customize the way you send and receive messages.

The Mail command is available for both the system mailbox and the personal mailbox.

The new message is stored in the system mailbox. By default, the user's system mailbox is a file that is located in the/var/spool/mail directory. The mailbox file is named after the user ID. For example, if the user identity is Jeanne, then the system mailbox is/var/spool/mail/jeanne.

By default, when a user reads, deletes, or saves all messages in their system mailbox, the mailbox is deleted. To either delete the mailbox, use the SET subcommand to set the Keep option.
Sign
-C Address (es) specifies a list of users to whom to send a copy of the message. You can specify one or more addresses. When more than one address is specified, the address list must be within quotation marks ("").
-e tests whether there are messages in the system mailbox. If there is a message to read, the mail utility does not write anything and exits with a successful return code.
-F FileName reads a message from the specified file. If no file operand is specified, the message is read from mbox. Messages that are not deleted are written to this file when you exit from the read message.
-F records the message in a file that is named after the recipient. The name is the first part of the address of the to: line in the message header. Overwrites the record variable if set.
-H writes only the title summary.
-I ignores the TTY interrupt signal.
-N Disables reading of the/usr/share/lib/mail.rc file.
-N Disables initial printing of headers.
-S Subject specifies the subject of the message that will be created.
The-u UserID specifies an abbreviation equivalent to executing mail-f/var/spool/mail/userid. Launches the mail program for the specified user's mailbox. You must have access permissions for the specified mailbox.
-V Resets the Mail program to verbose mode. Displays detailed information that is delivered to the user terminal.

Example

1. To start the mail program and list the messages in the mailbox, enter the following information at the command line prompt:

Mail

The Mail command lists each message in the system mailbox. The mail system then displays the mailbox prompt (? ) to indicate waiting for input. When you see this prompt, enter the MAILBOX subcommand. To view a list of subcommands, enter:
?

This entry lists the Mail subcommands.
2. To send the message letter to the recipient [email protected] and copy it to [email protected] and [email protected], please enter:

Mail-c "[email protected] [email protected]" [Email protected]<letter

3. To view the contents of your personal mailbox, enter:

Mail-f

This command displays a list of messages in the personal mailbox $HOME/mbox.
4. To view the contents of the specified mail folder, enter:

Mail-f +dept

This command displays a list of messages in the Dept folder.
5. To send a message to the user on the local system, enter:

Mail Ron

When you are finished entering the message into the user Ron, press Enter and. (period) or ctrl+d to exit the editor and send a message. To determine whether a user is on the local system, view the user name in the/etc/passwd file.

If the message is sent successfully, you will not receive a notification. If the message cannot be sent, an error message will be sent to you.
6. To send a file to another user on the local system by mail, enter:

Mail Karen < Letter1

This command sends the contents of the file Letter1 to the Local system user, Karen. After the command sends the file, the Mail program displays a command prompt.
7. To send a message to a remote system user, enter:

mail [email protected]

Now you can create a message to Dale. In this example, a message is sent to the Dale user on the remote system Zeus. To send a message to a user on another system connected to your system over the network, you must know the person's login ID and the name of another system.

The use of the Mail command under the Linux system

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.