This article mainly introduces the usage and analysis of the linuxmail command, explains the Mail sending method, the method for sending attachments, and the method for viewing emails. For more information, see
Here we will sort out the use of the mail command in Linux. Mail is also a common command. it is used in many places, such as regularly sending system conditions or logs to our mailbox.
First, use the help parameter to view all the mail parameters as follows:
Copy codeThe code is as follows:
Usage: mail [-BDFintv ~] [-S subject] [-a attachment] [-c cc-addr] [-B bcc-addr]
[-R from-addr] [-h hops] [-A account] [-R reply-addr] to-addr...
Mail [-BDeHiInNRv ~] [-T name] [-A account]-f [name]
Mail [-BDeinNRv ~] [-A account] [-u user]
1. send the title and text content
Run the following command:
Copy codeThe code is as follows:
Mail-s "this is a title" bbmonkey62@163.com
Press enter to continue entering text, that is, the Mail content
Copy codeThe code is as follows:
This is content
Then press Ctrl + D to exit.
Copy codeThe code is as follows:
EOT
The above is the simplest example. what if we want to send it to multiple mailboxes? Add another email address to the mailbox above. separate the email addresses with spaces, as shown below:
Copy codeThe code is as follows:
Mail-s "this is a title" bbmonkey62@163.com admin@163.com
In the above example, the sender is the current login user name of Linux, for example, my current login user name is admin, then the e-mail address sent is admin@163.com, if the mailbox suffix domain name is 163.com. But sometimes we want to write the sender's name and do not want to use the default email address. in this case, we can do this:
Copy codeThe code is as follows: mail-s "this is a title"-r "myname@zihou.me" bbmonkey62@163.com
At this time the sender mailbox is changed to myname@zihou.me, some spam is using this method, hiding their real mail address.
If you want the recipient to reply to an email, the email address is different from the email address, you can customize the email address as follows:
Copy codeThe code is as follows: mail-s "this is a title"-r "myname@zihou.me"-R "myreply@zihou.me" bbmonkey62@163.com
Then when the recipient replies, it will be sent to the myreply@zihou.me by default, rather than the default myname@zihou.me.
2. send attachments
Sometimes it is very easy to send attachments, as shown below:
Copy codeThe code is as follows:
Mail-s "this is a title"-r "myname@zihou.me"-a "/home/hadoop/report/3.txt" bbmonkey62@163.com
If our attachments are small text files, we sometimes do not need to send attachments. we can directly send the attachments as the email content, in this way, it is more convenient to view via email, as shown below:
Copy codeThe code is as follows:
Mail-s "this is a test" bbmonkey62@163.com
3. do not press enter to enter the email content to send the email
In the above example, if you follow the instructions, you will find it inconvenient, that is, each time you enter the Mail content, you must press enter to enter the content after running the command, finally, press Ctrl + D. In fact, you don't have to worry about it as follows:
Copy codeThe code is as follows:
Echo "this is content" | mail-s "this is a title" bbmonkey62@163.com
Input the email content "this is content" through the echo command, which is much simpler!
4. View emails
You can also view the received emails by using the mail command. let's just put it down. after all, this is relatively uncommon. the command is very simple. if you enter mail directly, the received emails will appear, each email corresponds to a serial number. if you want to view an email, go directly? Enter the serial number.
In? Enter help to view all the parameters, as shown below:
Copy codeThe code is as follows:
? Help
Mail commands
Type Type messages
Next goto and type next message
From Give head lines of messages
Headers print out active message headers
Delete Delete messages
Undelete Undelete messages
Save Folder append messages to folder and mark as saved
Copy Folder append messages to folder without marking them
Write File append message texts to file, save attachments
Preserve Keep incoming messages in mailbox even if saved
Reply Reply to message senders
Reply Reply to message senders and all recipients
Mail addresses mail to specific recipients
File folder change to another folder
Quit and apply changes to folder
Xit quit and discard changes made to folder
! Shell escape
Cd Chdir to directory or home if none given
List names of all available commands
A Consists of integers, ranges of same, or other criteria
Separated by spaces. If omitted, mail uses the last message typed.
In? You can also directly enter mail to write a letter, just like in the above example. The difference is that there will be a prompt in each step, as shown below:
Copy codeThe code is as follows:
? Mail
To: bbmonkey62@163.com
Subject: this is a title
Content
EOT