Install mailx
CentOS 7
Comes with mailx
the package, there are /usr/bin/mail
commands, configuration files /etc/mail.rc
.
If there is no package can be installed
- CentOS/Fedora
yum install -y mailx
Modify the configuration file
General mail service information will require a password, and mail server, modify the configuration file, add the relevant information directly modify the configuration file vim /etc/mail.rc
, added at the end:
# smtp服务器认证的用户名
set [email protected]
# smtp服务器的地址
set smtp=smtp.exmail.qq.com
# 邮件认证的方式
set smtp-auth=login
# smtp服务器认证的用户名
set [email protected]
# smtp服务器认证的用户密码(授权码)
set smtp-auth-password=test_password
# 忽略验证
set ssl-verify=ignore
set nss-config-dir=/etc/maildbs/
send email
Use direct mail command in a shell
mail -s "邮件主题" 收件人地址
Enter the above command execution, we will wait for user input when the input is completed, use the ctrl+D
key, end and send mail.
Use echo and pipes
echo "测试邮件" | mail -s "邮件主题" 收件人地址
echo "邮件内容" | mail -s "邮件主题" -a 附件 收件地址