邮件
mailx
安装
yum install mailx -y
查看版本
mailx -V
mailx的配置文件在/etc/mail.rz
set from="xxx@xxx.cn"
set smtp="smtps://smtp.mxhichina.com:465"
set smtp-auth-user="xxx@xxx.cn"
set smtp-auth-password="xxxxxx"
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/etc/pki/nssdb/
配置完后发送邮件会提示,证书没有获得认可
Error in certificate: Peer's certificate issuer has been marked as not trusted by the.
查看证书
openssl s_client -showcerts -connect smtp.qq.com:465
生成信任证书
echo -n | openssl s_client -connect smtp.mxhichina.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /kw/.certs/alimail.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d /kw/.certs -i /kw/.certs/alimail.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d /kw/.certs -i /kw/.certs/alimail.crt
certutil -L -d /kw/.certs
找个存放证书的目录 将/etc/pki/nssdb/改成/xx/.certs
set from="xxx@xxx.cn"
set smtp="smtps://smtp.mxhichina.com:465"
set smtp-auth-user="xxx@xxx.cn"
set smtp-auth-password="xxxxxx"
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/kw/.certs
配置完执行下面命令,这样就不会报错了。
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i alimail.crt
发送邮件方式
- 输入命令然后输入subject,在输入内容,按ctrl+d发送
mailx xxx@xxx.com
- 输入内容,按ctrl+d发送 可以加-v 选项来查看执行过程信息,注意:-v要写在-s之前,否者会提示语法错误,其实就是-s 后必须接title,就像这样(smtp-server: 501 Bad address syntax)
mailx -s "title" xxx@xxx.com
- 直接发送
echo "test" | mailx -s "title" xxx@xxx.com
- 利用文件作为内容发送
mailx -s "title" < test.txt xxx@xxx.com
或者
mailx -s "title" xxx@xxx.com < test.txt
- 发送附件
echo "test" | mailx -a "filename" -s "title" xxx@xxx.com
notice: 如果是阿里云需要设置安全组规则 端口号465/465
SMTP错误码/建议解决方法
https://blog.csdn.net/chenfei_5201213/article/details/10138969
监控用户登录的脚本,并登陆者的ip、登录方式,登录用户名发送到 xxx@xxx.com
#!bin/bash
loginCO=0 loginCL=who | wc -l#获取已登录用户列表 while true do if [[ "$loginCL" -gt 0 ]];then if [[ "$loginCL" -gt "$loginCO" ]];then #当新获取的用户数比旧用户数要多时 user=$(who | sed -n -e '$p' | awk '{print $1}') #取已登录用户列表的最后一个用户信息 clientNumber=$(who | sed -n -e '$p' | awk '{print $2}') time=$(who | sed -n -e '$p' | awk '{print $3"-"$4" "$5}') ip=$(who | sed -n -e '$p' | awk '{print $6}' | cut -d "(" -f2 | cut -d ")" -f1) echo -e "someone is logging! \nhere are some imformation for it :\n\nUser:$user \nClientNumber: $clientNumber\nTime: $time\nIP:$ip" > /tmp/mail/loginmail mailx -s "logging status" test@test.com < /tmp/mail/loginmail #test@test.com为接受邮件的邮箱 fi fi sleep 3 #等待3秒再次获取已登录用户数,这个时间越短检测成功率越高 loginCO=$loginCL loginCL=\who | wc -l`
done
`
转载:https://www.jianshu.com/p/5dd7ab8edd14