自学内容网 自学内容网

linux 下mailx 的使用。发送短信

1. 安装 mailx 

yum install -y mailx

2.请求数字证书

163 邮箱

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                         ####列出目录下证书

qq

mkdir -p /root/.certs/                           ####创建目录,用来存放证书
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt                    ####向163请求证书
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt                  ####添加一个SSL证书到证书数据库中
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt               ####添加一个Global 证书到证书数据库中
certutil -L -d /root/.certs                         ####列出目录下证书

3.修改配置文件

163

vim /etc/mail.rc

# 以下为文件中的内容

set bsdcompat
set from=xxx@163.com
set smtp=smtps://smtp.163.com:465
set smtp-auth-user=xxx@163.com
set smtp-auth-password=授权密码
set ssl-verify=ignore
set nss-config-dir=/root/.certs
set smtp-auth=login

qq

vim /etc/mail.rc

# 以下为文件中的内容

set bsdcompat
set from=xxx@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=xxx@qq.com
set smtp-auth-password=授权密码
set ssl-verify=ignore
set nss-config-dir=/root/.certs
set smtp-auth=login

说明:

set from=user@xxx.com               # 设置发信人邮箱和昵称

set smtp=smtps://smtp.xxx.com:465   # 这里填入smtp地址

set smtp-auth-user=user@xxx.com     # 这里输入邮箱账号

set smtp-auth-password=password     # 这里填入授权密码

set ssl-verify=ignore               # 忽略证书警告

set nss-config-dir=/root/.certs   # 证书所在目录
set smtp-auth=login                 # 认证方式
#set smtp-use-starttls=yes          # STARTTLS时使用

多用户:

account wangyi  {
set bsdcompat
set from=xxx@163.com
set smtp=smtps://smtp.163.com:465
set smtp-auth-user=xxx@163.com
set smtp-auth-password=授权密码
set ssl-verify=ignore
set nss-config-dir=/root/.certs
set smtp-auth=login
}
account qq {
set bsdcompat
set from=xxx@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=xxx@qq.com
set smtp-auth-password=授权密码
set ssl-verify=ignore
set nss-config-dir=/root/.certs
set smtp-auth=login
}

4. 证书不被信任

# 依次执行以下内容

cd /root/.certs/

ll

certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i 163.crt

如果提示:Notice: Trust flag u is set automatically if the private key is present.表示添加成功

5. 测试:

echo “test” | mail -s "主题"  邮箱地址

# 添加附件 附件为 hello.log 

echo “正文内容” | mail -a hello.log -A qq -s "主题"  xxx@qq.com

-a: 附件

-A: 账户 (配置在 mail 文件中,使用与多用户情况)

说明:

三种常用方式:

echo '邮件内容' | mail -s '邮件标题' 收件人邮箱

cat 邮件内容.txt | mail -s '邮件标题' 收件人邮箱

mail -s '邮件标题' 收件人邮箱 < 邮件内容.txt

6. 发送qq 邮箱报错:Error in certificate: Peer’s certificate issuer is not recognized

cd /root/.certs/
ll
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt

原文地址:https://blog.csdn.net/weixin_42550387/article/details/142583539

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!