Mail 配置脚本

作者: admin 分类: Linux,Shell脚本 发布时间: 2023-04-21 13:18 浏览:1,101 次    
#!/bin/bash

mail_name=xxxx@126.com     # 发送邮件地址
mail_user=xxxx@126.com     # 发送邮件地址
mail_passwd=password       # 密码(一般为授权码)
mail_smtp=smtp.126.com     # smtp服务器地址
cert_dir=/root/.certs/     # 证书存放目录
cert_name=126.crt          # 证书名称
conf_file=/etc/mail.rc     # 配置文件

#创建证书
cert_mk()  
{
mkdir -p $cert_dir
echo -n | openssl s_client -connect $mail_smtp:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > $cert_dir/$cert_name
certutil -A -n "GeoTrust SSL CA" -t "C,," -d $cert_dir -i $cert_dir/$cert_name
certutil -A -n "GeoTrust Global CA" -t "C,," -d $cert_dir -i $cert_dir/$cert_name
certutil -L -d $cert_dir
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d $cert_dir -i $cert_dir/$cert_name
}

#mail配置
mail_cfg()
{
cat >>$conf_file <<EOF
#mail auth config
set smtp=smtps://$mail_smtp:465    #加密smtp端口为465
set from=$mail_name
set smtp-auth-user=$mail_user
set smtp-auth-password=$mail_passwd
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=$cert_dir
EOF
}

man()
{
pkg=$(rpm -qa | grep mailx | wc -l)
if [ $pkg == 0 ];then
yum install mailx -y
mail_cfg
cert_mk
else
mail_cfg
cert_mk
fi
}

man

测试

echo "mail test ok" | mailx -v -s "test" xxx@163.com
  • mail test ok 邮件内容
  • test 邮件的标题
  • xxx@163.com 接收邮件的账号

温馨提示:如无特殊说明,本站文章均为作者原创,转载时请注明出处及相应链接!

发表评论