Linux mail command parameters, linuxmail

Source: Internet
Author: User

Linux mail command parameters, linuxmail


When using mail to send emails, you must first start the sendmail service.

Mail-s "subject"-c "CC address"-B "BCC address" ---f sender email address-F sender name <content of the email to be sent

Send emails in three common formats
Mail-s test yangfang@fudan.edu.cn # The first method, you can use the current shell as the editor, edit the content after Ctrl-D end
Echo "mail content" | mail-s test yangfang@fudan.edu.cn # the second method, I use the most, may be like the reason for Pipeline
Mail-s test yangfang@fudan.edu.cn <file # The third method, mail with file content as the mail content

1. Specify a specific sender:

$ Mail-s "just a test" recipient's email address <the email content file to be sent ---f sender's email address-F sender's name
The result is that the mail content will be sent to the recipient's mailbox. The displayed sender is the sender's name <sender's email address>, and the displayed content is the content of the sent email...

2. Send a MAIL containing the command execution result:

Echo-e 'ls/tmp '| mail-s "test" fff@aaa.com </tmp/dd.txt ---f cc@aaa.com-F cc

3. Available options

S mail title.
C cc address.
B bcc mail address.
I ignore tty interrupt signals. (Interrupt)
I forced the interaction mode. (Interactive)
V prints a message, such as the location and status of the mail. (Verbose)
N does not read the mail. rc configuration file.

The sendmail or postfix service is required.

4. You can use
Cat xxxx.txt | mail-s "theme" abc@xxx.com fff@xxx.com

5. To send attachments, install uencode (yum install sharutils)

A single attachment is sent, and xxxx@xxx.comreceives an attachment from data.txt.
Uuencode/tmp/data_process.log data.txt | mail xxx@xxx.com
If you need to send the text together with the attachment:
Uuencode/tmp/data_process.log data.txt>/tmp/data_temp.txt

6. emails received by the system are saved in the "/var/spool/mail/[linux User Name]" file. In linux, enter mail to go To the inbox and display the list of 20 emails.

At this time, the command prompt is "&": (you can enter the following command to perform relevant operations on the mail)
Unread mark as unread mail
H | headers: displays the current mail list
L | list displays the list of currently supported commands
? | Help command parameter usage for displaying multiple mail lists
D. Delete the current email, and move the pointer down. D 1-100 Delete 1st to 100 emails
F | from only displays the simple information of the current email. F num: displays the simple information of an email.
F | from num pointer to an email
Z displays the last 20 emails in the inbox.
More | p | when reading the email content of the current pointer on the page, press the Space key to flip the page, and press the Enter key to move down a row
T | type | more | p | page num read an email
N | next | {do not fill in anything} when reading the content of the next email containing the current pointer, press the Space key to flip the page, and press the Enter key to move down a line
V | visual current mail enters the plain text editing mode
Top displays the mail header of the email with the current pointer
File | folder: displays the file of the system email and the total number of emails.
Exit the mail command platform and do not save the previous operations, such as deleting emails.
Q: log out of the mail command platform and save the previous operations. For example, if you delete an email that has been deleted by d, the read email will be transferred to the mbox file in the current user's home directory. If you delete a file in mbox, it will be permanently deleted. On the linux text command platform, enter mail-f mbox to view the emails in the mbox in the current directory.
Cd changes the location of the current folder
When writing a letter, press Ctrl + C twice to stop working.
Press Ctrl + C once to exit reading.

Use the linux mail command to send an email:
1. Send the file as an email

Syntax: mail-s "topic" username @ address <File
For example:
Mail-s "program" user <file. c uses file. c as the mail content and sends it to the user with the topic program.

2. send an email to the user of the system.

Syntax: mail User Name

3. Send an email to a foreign user

Syntax: mail username @ accept address
... /Usr/lib/sendmail-bp
...... "Mail queue is empty "...... Mail ....
For example:
Mailtest@hotmail.com
Subject: mail test
:
Enter Text Content
::
Press Ctrl + D or. to end the text.
Press Ctrl + C twice to interrupt the work. Do not send this letter.
Cc (Carbon copy): copy the text to another recipient.

4. Send the email to one or more email addresses.
Because no other options are added, the user must enter the title and the content of the letter. If user2 does not have a host location, it is sent to the user2 user on the email server.

Mail user1@email.address
Mail user1@email.address user2
Send mail.txt content to user2 and cc to user1. If you set this line of command to cronjob, You can regularly send the memorandum to the System user.
Mail-s title-c user1 user2 <mail.txt

5. Check whether the sent email is sent or stuck on the email server.

Syntax:/usr/lib/sendmail-bp
If "Mail queue is empty" is displayed on the screen, mail has been sent.
Other error messages indicate that the email has not been sent for any reason.

6. Use an external email address to send emails to linux mail
By default, bin/mail will use local sendmail to send emails. This requires that the local machine must install and start the Sendmail service, which is very troublesome to configure and will cause unnecessary
Resource usage. By modifying the configuration file, you can use an external SMTP server to send emails without using sendmail:
Modify/etc/nail. rc (/etc/mail. rc)
Set from = fromUser@domain.com smtp = smtp. domain. comset smtp-auth-user = username smtp-auth-password = passwordset smtp-auth = login
Note:
From is the sent email address.
Smtp is the address of the external smtp server.
Smtp-auth-user is the user name authenticated by the external smtp server.
Smtp-auth-password is the user password authenticated by the external smtp server.
Smtp-auth is the mail authentication method.
After the configuration is successful, you can use
You can send an email to test it:
Mail-s "test" user@sohu.com <content.txt followed by the mail, user@sohu.comis the recipient's address, content.txt inside is the mail body

Source: http://www.cnblogs.com/toowang/p/3920465.html

 

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.