The simple implementation of Linux uses the local mailbox or external mailbox server to send, which is commonly used for server monitoring alarm log sending and archiving.

Operation steps:

1. Installation

yum install mailx -y

2. Change configuration

edit vi /etc/mail.rc Add the following information to the last line:

 set from= test@163.com ###Set sender's information here set smtp=smtp.163.com ###The mail service address is configured here. Since the mailbox is 163, it is smtp.163.com set smtp-auth-user= test@163.com ###Configure sender's email address here set smtp-auth-password=abc ###Remember that the abc configured here is the client authorization code, not the sender's email address password set smtp-auth=login ###Default authentication method of mail

3. Test sending

Echo "Test content" | mail - s "Test mail" xx@163.com

4. Script

#!/ bin/bash

 help(){ echo "eg: $0 [Subject] [address] [content_file] [file]" echo "" exit 1 } if [ ! - n "$1" ] ; then help fi cDate=`date +%Y%m%d` if [ ! - n "$2" ] ; then help else mail_to=$2 echo "      Send Mail to ${mail_to}" fi if [ ! - n "$4" ] ; then mail -s $1 ${mail_to}<$3 else mail -s $1 -a $4 ${mail_to}<$3 fi

5. Usage:

./sendmail.sh The contents of the recipient's mailbox (file, such as 1. txt)