Centos通过Shell发送邮件
2025-01-01 16:44:22
Centos通过Shell发送邮件方法:
安装mailx:yum install -y mailx
如果通过163邮箱发送就需要申请一个授权码
vi /etc/mail.rc添加如下配置
set from=163user@163.com #发件人邮箱
set smtp=smtps://smtp.163.com:465 #使用SSL下的465端口
set smtp-auth-user=163user@163.com #登录用户名
set smtp-auth-password=XXXXXXXXX #邮箱授权码,在QQ邮箱设置界面发短信生成
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs
请求数字证书
依次完成以下命令
mkdir -p /root/.certs/ ####创建目录,用来存放证书
echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt ####向163请求证书
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt ####添加一个SSL证书到证书数据库中
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt ####添加一个Global 证书到证书数据库中
certutil -L -d /root/.certs ####列出目录下证书
解决最后一个证书不被信任问题
按以下命令依次输入
cd /root/.certs/
ll
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i 163.crt
最后可以测试了:
echo "Hello Jn,这里是邮件正文." | mail -s "邮件主题" 11122233@qq.com
安装mailx:yum install -y mailx
如果通过163邮箱发送就需要申请一个授权码
vi /etc/mail.rc添加如下配置
set from=163user@163.com #发件人邮箱
set smtp=smtps://smtp.163.com:465 #使用SSL下的465端口
set smtp-auth-user=163user@163.com #登录用户名
set smtp-auth-password=XXXXXXXXX #邮箱授权码,在QQ邮箱设置界面发短信生成
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs
请求数字证书
依次完成以下命令
mkdir -p /root/.certs/ ####创建目录,用来存放证书
echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt ####向163请求证书
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt ####添加一个SSL证书到证书数据库中
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt ####添加一个Global 证书到证书数据库中
certutil -L -d /root/.certs ####列出目录下证书
解决最后一个证书不被信任问题
按以下命令依次输入
cd /root/.certs/
ll
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i 163.crt
最后可以测试了:
echo "Hello Jn,这里是邮件正文." | mail -s "邮件主题" 11122233@qq.com