Send e-mail through the shell

Install mailx

CentOS 7Comes with mailxthe package, there are /usr/bin/mailcommands, 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+Dkey, end and send mail.

Use echo and pipes

echo "测试邮件" | mail -s "邮件主题" 收件人地址

echo "邮件内容" | mail -s "邮件主题" -a 附件 收件地址

Guess you like

Origin www.cnblogs.com/zzhaolei/p/11068133.html