每次在 Linux 下写脚本都有发送邮件的功能 ,但是在 Linux 下的配置老是忘记,所以这次写了个小脚本,记录下,下次要配置时运行一下脚本就行了。这里使用的是 QQ 邮箱.
测试环境:CentOS 6.5 x86_64
脚本内容如下:
- # ! /bin/bash. / etc / init.d / functions
- if [ $# - ne 0 ];
- then echo "Usage: sh `basename $0`" exit 1 fi
- smtp_host = 'smtp.qq.com'
- smpt_auth_password = 'mdkuasfhnjbrbhdj'certs_dir = /root/.certs mail_conf = /etc/mail.rc content = `cat $mail_conf | grep 'smtp - auth - user'`
- if [ "x$content" != "x" ];
- then action "'$mail_conf' 文件已经配置" / bin / true exit 1 fi cat >> $mail_conf < $certs_dir / qq.crt certutil - A - n "GeoTrust SSL CA" - t "C,," - d $certs_dir - i $certs_dir / qq.crt certutil - A - n "GeoTrust Global CA" - t "C,," - d $certs_dir - i $certs_dir / qq.crt certutil - L - d $certs_dir[ $ ? - eq 0 ] && action "生成证书" / bin / true
在 root 用户下执行:
- sh auto_mail_configure.sh
执行完成
接下来执行下面的命令进行测试:
- echo hello word | mailx - v - s " title"
查看有没有收到邮件:
来源: http://www.bubuko.com/infodetail-1862476.html