CentOS is VPS encyclopedia's favorite Linux system and the benchmark system for many related tutorials. However, CentOS cannot send emails by default. Children's shoes that need to send emails can install a sendmail program.
Install sendmail
Execution:
yum -y install sendmail
The program will automatically search for the sendmail installer and install it automatically.
After installing sendmail, execute the following command to start sendmail
service sendmail start
After startup, we can execute the mail command to test whether the mail can be sent
1、 Send mail from file content
First create a body.txt
# touch body.txt
Write content
echo ' This is test mail
'>body.txt
Send Mail
mail -s 'Test mail' [email protected] < body.txt
I got the mail in a minute
Click Open, and the body content is the content of body.txt
This is test mail
2、 Send mail content directly with pipeline character
If you do not want to send the mail content through a file, you can also send it this way
echo " This is test mail
" | mail -s 'Test mail' [email protected]
The above effect is the same as the content of the email sent by the file
If you are prompted by mail: command not found
-bash: mail: command not found
The mail command is not installed. You need to install the mail command at this time
yum install mailx -y
Then resend the following email!
In particular, if a firewall is installed, please add the following rules:
Iptables settings
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -A INPUT -p udp --dport 25 -j ACCEPT
Sendmail Common Commands
1. View messages in process
/usr/lib/sendmail -bp
2. Clear unsuccessful messages
rm -rf /var/spool/mqueue/*
Startup settings of sendmail service
chkconfig --level 35 sendmail on
Start up command.