How to send a mailbox directly using the linux mail command

Source: Internet
Author: User

In linux, the mail command can be used to send emails like in php, but the mail function requires simple configuration to send emails. Let's take a look at it.


Mail configuration

Configure the new version of mailx to send emails using an external mailbox:

 
Edit/etc/nail. rc (note that it is not the old version/etc/mail. rc): vi/etc/nail. rc
 
Add two rows:
 
Set from = myname@qq.com smtp = smtp.qq.com
Set smtp-auth-user = myname smtp-auth-password = password smtp-auth = login


Test the mail command in Linux

1. The simplest example:

Mail-s test yangfang@fudan.edu.cn

The result of this command is to send an empty letter named test to the mailbox behind it. If you have an mta and the mailbox behind it won't block this strange message, you will be able to receive this letter. If you do not want to be disturbed by such a mess, use a local account for your mailbox.


2. Example 2:

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

In fact, you can easily find that mail reads the file content from the standard input and sends a mail. I just want to let you know this. Here, the second example ends.

3. In the third example, emails with attachments

If you do not have the uuencode command in your system, install sharutils (yum install sharutils) first)

Uuencode requires two parameters. The first one is the file you want to send (you). Of course, this can also be done using pipelines, and the second one is the file name displayed.

Uuencode/home/yfang/a.gif | mail-s pictest yangfang@fudan.edu.cn

Tar czf-/home/yfang/| uencode home. tgz | mail-s pictest yangfang@fudan.edu.cn

Ps: By the way, the mail in slackware seems to have a-a parameter. You can add attachments directly. I have never used it.


In linux, enter mail to go To the inbox and display the list of 20 emails.

The command prompt is "&"
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} read the content of the next email containing the current pointer
When reading, pressing the Space key is to flip the page, and pressing the Enter key is to move down a row
V | visual current mail enters the plain text editing mode
N | next | {do not fill in anything} num reads an email
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.

Slow email sending

Generally, sendmail is used in linux and mail () is used in php to send emails slowly. This is caused by slow DNS resolution, and is often because the hostname of the server is not a real domain name that can be parsed. To solve this problem, make sure that:
[*]/Etc/mail/local-hosts-names domain names appear in/etc/hosts; [*] the hostname must be a real resolved domain name. You can use the hostname -- help Command to modify the hostname of a linux system.

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.