CentOs6 system install mailx to send mail

1. yum -y mail* sendmail* postfix*
service sendmail start
2. cp /etc/mail.rc /etc/mail.rc.bak
cat > /etc/mail.rc<<EOF
set from=youname@rekfan.com
set smtp=smtp.rekfan.com
set smtp-auth-user=youname
set smtp-auth-password=youpassword
set smtp-auth=login
EOF

3. Send email to verify

echo "test" | mail -v -s "test" youname@rekfan.com

If the following picture appears, it means that the email was sent successfully. If it is not sent successfully, check according to the error message.

Send mail with mail command under linux

4. Three commonly used formats for sending letters

mail -s test [email protected] #In the first method, you can use the current shell as an editor. After editing the content, Ctrl-D can enter the CC, which can be separated by a comma, and sent after the carriage return.
echo "mail content"|mail -s test [email protected] #The second method, use the pipeline
mail -s test [email protected] <file #The third method, use the content of the file as the mail content to send a letter

Send attachments

If there is no uuencode command in your system, please install sharutils first (yum install sharutils).
uuencode requires two parameters. The first is the file(s) you want to send. Of course, this can also be done using a pipeline, and the second Is the displayed file name
uuencode 1.txt 1.txt | mail -s test2 [email protected] (text file under linux is best to be unix2dos first)
tar zcf – /tmp/1/ |uuencode 1.tgz | mail -s test1 [email protected]

Both attachment and message body

Write your email first, such as mymail, then
uuencode <attachment file name> <attachment file name> >> mymail
or cat <attachment file name> | uuencode <attachment file name> >> mymail
and edit your mymail file, in front Write the body of the letter. Then send it out.
Actual operation: echo'hello zhengwen
' >zhengwen.txt
cat 1.gif | uuencode 1.gif>>
zhengwen.txt cat zhengwen.txt |mail -s test1 [email protected]

Send the letter to one or more email addresses.
mail -s title -c user1 user2 <mail.txt
mail -s biaoti [email protected] -c [email protected] -b [email protected] <1.txt

Check whether the sent e-mail is sent, or is stuck in the mail server.
Syntax: /usr/lib/sendmail -bp
If the message "Mail queue is empty" is displayed on the screen, it means that the mail has been sent.
If it is another error message, it means that the email has not been sent for some reason.

Attached:

linux mail command parameters:
i ignore the interrupt signal of tty. (interrupt)
I Forced to be set to interactive mode. (Interactive)
v Print out messages, such as the location and status of the message. (verbose)
n Do not read the mail.rc configuration file.
s The title of the message.
c cc email address.
b bcc email address.

All emails received by the system will be saved in the file "/var/spool/mail/[linux username]". Enter mail in linux, the inbox is performed, and a list of twenty mails is displayed.

At this time, the command prompt is "&": (You can enter the following commands to perform related operations on the mail)
& help //If you don’t use or forget any command, enter help or? to get help
Mail Commands
t Print out the information [ Note] Multiple messages are separated by spaces, such as t 1 7
n to print out the next message
e to edit the message
f to output the header line of the
message d to delete the message
s file to append the message to the file
u do not delete a certain message
R reply to the sender
r reply The sender and all recipients of this message
pre keep the information in /usr/spool/mail 1*
m Send mail, multiple recipients are separated by spaces [requires sendmail support]
q quit, saving unresolved messages in mbox 2*
x quit, do not remove system mailbox
h print out active message headers
! Let the shell execute a command, such as !ls output the result of the ls command
cd [directory] to change the directory, here you don’t need !cd, but you need !pwd to print the current directory

Guess you like

Origin blog.csdn.net/ichen820/article/details/115252645