Centos6.x use the mail command to send an email

Source: Internet
Author: User

Centos6.x use the mail command to send an email
Use the mail command to send an email

Because you often need to back up website data, you have learned how to send emails through shell in linux. Here, we use CentOS as an example to use the mail command to send external emails. The syntax of the mail command is as follows:

1

2

3

4

Usage: mail [-iInv] [-ssubject] [-ccc-addr] [-bbcc-addr] to-addr...

[-- Sendmail-options...]

Mail [-iInNv]-f [name]

Mail [-iInNv] [-uuser]

You can use the mail command to send emails in the following three ways:

1. directly use shell as the editor

1

2

3

Mail-s "Hello from mzone. cc by shell" admin@mzone.cc

Hello, thisisthecontentofmail.

Welcometowww. mzone. cc

The first line is the input command,-s indicates the subject of the mail, followed by the admin@mzone.cc is the recipient of the mail, enter this line of command and press enter, will enter the body of the mail writing, we can enter any text, such as the above two lines. After entering the body of the email, press CTRL + D to complete the input. At this time, you will be prompted to enter the Cc address, that is, the Cc address. If you do not press enter, the email will be sent.

2. Use MPs queues to send emails

1

Echo "hello, this is the content of mail. welcome to www. mzone. cc" | mail-s "Hello from mzone. cc by pipe" admin@mzone.cc

You can use the pipeline to directly input this line of command to send the mail. The echo is the mail body.

3. Use files to send emails

1

Mail-s "Hello from mzone. cc by file" admin@mzone.cc <mail.txt

With the imperative, we can send the contents of the mail.txt file to the admin@mzone.cc as the mail content.

The above three methods can be used to send emails to external mailboxes. However, because the first two methods directly input the email content in shell, the Chinese characters cannot be entered, even if we use the paste method to input Chinese characters, the emails we receive are garbled. However, in the following 3rd methods, you can edit the email content in the window and put it in linux before sending the email. In this way, you can send the Chinese text normally. However, no solution is found for the Chinese title of the email.

Because the mail program itself calls sendmail to send mails, we can use the sendmail parameter in the mail command for configuration. For example, if I want to use a specific sender to send mails, run the following command:

1

Mail-s "Hello from mzone. cc with sender" admin@mzone.cc --- fuser@mzone.cc <mail.txt

In the above command, we used a parameter like--f user@mzone.cc, which is the sendmail option, where-f Represents the mail sender's mail address. For more sendmail parameters, see http://www.courier-mta.org/sendmail.html,#man sendmail in shellfor help.

In many cases, we also need to use emails to send attachments. in linux, It is also easy to use the mail command to send attachments. However, we need to install the uencode package first, this program is used to encode binary files so that they can be sent by email. install the software package on CentOS as follows:

1

Yuminstallsharutils

After the installation is complete, we can send the attachment by running the following command:

1

Uuencodetest.txt test | mail-s "hello, see the attachement" admin@mzone.cc <mail.txt

After completion, you can send the text.txt file as an attachment to the email. Uuencode has two parameters: the first parameter is the file to be sent, and the second parameter is the name of the displayed file.

Here I will mainly introduce some usage methods for sending emails using mail in CentOS. The requirement is that sendmail must be installed and enabled in linux, and the Internet can be connected at the same time. In addition, the commands mentioned in this article have all been tested in person to ensure full availability. However, you need to replace the email address in the command with your own email address.

With this mail Command, we have an additional tool in linux, perfect ^_^

Original address: http://www.mzone.cc/article/317.html

Counterfeit sender method:
Centos 6.x Heirloom Mail version 12.4 7/29/08. Type? For help.

You can specify the built-in Mail parameters as follows:

1

# Echo hello | mail-s '000000'-r from@xxxxx.com to@xxxxxx.com

Centos 5.x Mail version 8.1 6/6/93. Type? For help.
When using Linux mail to send emails, the sender can be forged. In other words, we can specify any sender.
The usage is as follows:

1

# Echo hello | mail-s '000000' to@foxmail.com ---f from@xxxxx.com

Note that there are two short bars plus one-f to keep up with the sender address.

This method is not only verified by the local senmail server, but also by the sohu mail server we mentioned earlier.
Therefore, emails can be forged. Pay attention to security ..

Postscript:
Such a system seems insecure. In fact, this is the same as an example in real life.
In our daily life, we can send or send express mail. In the sender column, we can leave it empty or enter it as needed, and the postman will not review it with you.
When we receive a letter, we don't actually know who sent it. When we see a familiar name on the sender, we can guess who sent it to ourselves.
Illegal personnel can send bombs, viruses, and so on via emails. There is already a precedent for these events.
In a computer network, the router does not check the source address (sender) for IP packet processing, so that criminals can use forged source IP addresses to cause DDOS attacks or DrDDOS attacks.

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.