Linux Mail Command parameters

Source: Internet
Author: User


When you use mail to send mail, you must first start the SendMail service.

mail–sMessage subject –c CC address –b---F sender e-mail address –F sender name < message content to send

Three commonly used formats for sending letters
Mail-s test [email protected] #第一种方法, you can use the current shell as an editor, finish editing the content ctrl-d end
echo "Mail Content" |mail-s test [email protected] #第二种方法, I used the most, probably like the plumbing for the sake of it
Mail-s test [email protected] < file #第三种方法 to send the contents of the file to the message

1. Specify a specific sender:

$ mail-s "Just a test" recipient email address < message content file to be sent---F sender e-mail address-F sender Name
The effect is: the contents of the letter will be sent to the recipient's mailbox, the sender's name < sender's email address is displayed, and the contents of the message are sent ...

2. Mail sent with the result of command execution:

Echo-e ' ls/tmp ' |mail-s "test" [email protected] </tmp/dd.txt---f [email protected]-F CC

3. Available options

s message header.
c CC CC email address.
b bcc secret delivery email address.
I ignore the interrupt signal of the TTY. (interrupt)
I forced to set into interactive mode. (Interactive)
V Print out a message, such as the location, status, etc. of the courier. (verbose)
n does not read into the Mail.rc profile.

Requires SendMail or postfix service

4, if the simple file can be used to send files
Cat Xxxx.txt |mail-s "keynote" [email protected] [email protected]

5, if need to send accessories need to install uuencode to encode (yum install sharutils)

Send the attachment separately so [email protected] will receive a data.txt attachment
Uuencode/tmp/data_process.log data.txt |mail [email protected]
If you want the body and attachments to be sent together:
Uuencode/tmp/data_process.log data.txt >/tmp/data_temp.txt

6, the system received the message 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.

At this point, the command prompt is "&": (You can enter the following command to work with the message)
Unread messages marked as unread
H|headers Display the current mailing list
L|list displays a list of currently supported commands
?| Help displays multiple command parameter usages to view the mailing list
D Delete the current message, and move the pointer down. D 1-100 Delete the 1th to 100th e-mail
F|from only displays simple information about the current message. F num Displays easy information for a single message
F|from num pointer moves to a message
Z Displays the following 20 mailing lists when you first make your inbox
More|p|page reading the contents of the current pointer, press SPACEBAR to page, press ENTER to move down one line
T|type|more|p|pageNum reads an e-mail message
N|next| {Nothing to fill} read the next message in the current pointer when reading, press the SPACEBAR is the page, press the ENTER key to move down one line
V|visual current message into plain text edit mode
Top Displays the message header of the message that contains the current pointer
File|folder display the file where the system mail is located, and the total number of messages
X exits the Mail command platform and does not save previous operations, such as deleting messages
Q quit the mail command platform to save previous operations, such as deleting deleted messages with D, and the read messages will be dumped into the mbox file in the current user's home directory. Deleting a file in mbox is completely removed. In the Linux text command platform input mail-f mbox, you can see the current directory of mbox in the mail.
CD changes the location of the current folder
When writing a letter, press the CTRL + C key two times to interrupt the work and not send this letter.
When reading a letter, press CTRL + C to exit the reading state.

To send a message using the Linux Mail command:
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 mail content, sent 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. Send the letter to one or more e-mail addresses.
As no other options are added, the user must enter the title and the contents of the letter. User2 does not have a host location and will be sent to the mail server's user2 users.

mail [email protected]
mail [email protected] User2
Send the contents of Mail.txt to User2 and CC to User1. If you set this line of instructions to cronjob, you can periodically send the memo to the system user.
Mail-s title-C User1 User2 < Mail.txt

5. 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.

6, Linux Mail use external email address to send mail
Bin/mail will send mail by default using local SendMail, which requires the local machine to install and start the SendMail service, which is cumbersome to configure and will cause unnecessary
Resource consumption. By modifying the configuration file, you can use an external SMTP server to send mail with an external SMTP server without using SendMail:
Modify/etc/nail.rc (/etc/mail.rc)
Set [email protected] Smtp=smtp.domain.comset smtp-auth-user=username smtp-auth-password=passwordset smtp-auth=login
Description
From is the e-mail address sent
SMTP is the address of the external SMTP server that occurs
Smtp-auth-user is an external SMTP server authenticated user name
Smtp-auth-password is the user password for external SMTP server authentication
Smtp-auth is the way of email authentication
Once the configuration is successful, you can use the
You can send a message to test:
Mail-s "Test" [email protected] <content.txt where-S is the message header, [email protected] is the recipient address, content.txt inside the message body

This article originated from: http://www.cnblogs.com/toowang/p/3920465.html

Linux Mail Command parameters

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.