Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the mail command in linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How do I use the mail command in linux? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.

First, use the help parameter to view all the parameters of mail as follows:

The code is as follows:

Usage: mail [- BDFintv~] [- s subject] [- an attachment] [- c cc-addr] [- b bcc-addr]

[- r from-addr] [- h hops] [- An account] [- R reply-addr] to-addr...

Mail [- BDeHiInNRv~] [- T name] [- An account]-f [name]

Mail [- BDeinNRv~] [- An account] [- u user]

1. Send the title plus text content

Run the command:

The code is as follows:

Mail-s "this is a title" bbmonkey62@163.com

Enter and continue to enter the text, that is, the content of the email

The code is as follows:

This is content

Then press Ctrl+D to exit.

The 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, separated by a space, as follows:

The code is as follows:

Mail-s "this is a title" bbmonkey62@163.com admin@163.com

In the above example, the sender is Linux's current login user name, for example, if my current login user name is admin, then the email 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 we don't want to use the default email address, so we can do this:

The code is as follows:

Mail-s "this is a title"-r "myname@zihou.me" bbmonkey62@163.com

At this point, the sender's mailbox becomes myname@zihou.me, and some spam emails use this method to hide their real email addresses.

If we want the recipient to reply to an email with a different email address than our outgoing email address, we can customize the reply email address as follows:

The 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 myreply@zihou.me by default, not to the default myname@zihou.me.

2. Send attachments

Sometimes we need to send attachments, then it is very easy, as follows:

The code is as follows:

Mail-s "this is a title"-r "myname@zihou.me"-a "/ home/hadoop/report/3.txt" bbmonkey62@163.com

To be explained here, if our attachment is a small text file, sometimes we do not need to send the attachment. We can directly send the text of the attachment as the content of the email, so it is more convenient to view it through the email, as follows:

The code is as follows:

Mail-s "this is a test" bbmonkey62@163.com < / home/hadoop/project/3.txt

3. There is no need to enter the content of the email to send the email.

In the above example, if you do this, you will find it very inconvenient, that is, each time you enter the content of the email, you need to enter the content after the command runs, and finally press Ctrl+D to complete it. In fact, it doesn't have to be so hard, as follows:

The code is as follows:

Echo "this is content" | mail-s "this is a title" bbmonkey62@163.com

Enter the email content "this is content" through the echo command, which is much easier!

4. Check email

Through the mail command can also check the received mail, this I will briefly say, after all, this is relatively rare, the command is very simple, directly enter mail, there will be received mail, each email corresponds to a serial number, if you want to view an email, directly in? Then enter the digital serial number.

In? Enter help to view all the parameters, as follows:

The 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 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 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 type mail directly to write a letter later, just like the example above, except that there will be a prompt for each step, as follows:

The code is as follows:

? Mail

To: bbmonkey62@163.com

Subject: this is a title

Content

EOT

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report