使用mailx发送邮件
作者:互联网
1. 安装邮件服务(默认此服务已安装)
yum -y install postfix
2. 安装邮件发送工具mailx 在配置文件后面加入以下配置
yum -y install mailx
2.1 465端口认证配置
vim /etc/mail.rc
# 最后加入以下邮件配置
set from=alarm@xxx.com.cn # 发送者邮箱
set smtp=smtps://smtp.exmail.qq.com:465 # ssl验证
set smtp-auth-user=alarm@xxx.com.cn # 发送者邮箱
set smtp-auth-password=xxxxx # 密码
set nss-config-dir=/etc/mail/scripts/.certs # 证书目录
# set ssl-verify=ignore
set smtp-auth=login
# ssl证书生成
mkdir -p /etc/mail/scripts/.certs
echo -n | openssl s_client -connect smtp.exmail.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /etc/mail/scripts/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d /etc/mail/scripts/.certs -i /etc/mail/scripts/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d /etc/mail/scripts/.certs -i /etc/mail/scripts/.certs/qq.crt
certutil -L -d /etc/mail/scripts/.certs/
cd /etc/mail/scripts/.certs/ && certutil -A -n "GeoTrust SSL CA – G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
2.2 25端口方式认证配置
set from=alarm@xxx.com.cn
set smtp=smtp.exmail.qq.com
set smtp-auth-user=alarm@xxx.com.cn
set smtp-auth-password=xxxxx
set smtp-auth=login
3. 发送带附件的邮件
echo "test-mail" | mail -s "测试邮件附件" -a /root/sh/flink_status.sh.bak 1550789579@qq.com
-s # 主题信息
-a # 附件路径
标签:set,mailx,smtp,发送,etc,certs,scripts,mail,邮件 来源: https://www.cnblogs.com/longliz/p/16348183.html