mail命令发送邮件

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

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

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

QQ邮箱开启smtp服务

安装

yum -y install sendmail mailx libreport-plugin-mailx sharutils mutt

修改配置文件

vim /etc/mail.rc  #以下内容在文件末尾添加
#set from=64688483@qq.com(彭于晏)  #设置发信人姓名和邮箱
set from=64688483@qq.com  #设置发信人邮箱
set smtp=smtp.qq.com      #邮件服务器
set smtp-auth-user=64688483@qq.com  #设置邮箱账号
set smtp-auth-password=ffboyhrr     #授权码或密码
set smtp-auth=login  #默认login

发送邮件验证

echo "Hello worlad"|mail -s "test" 201448247@qq.com

使用阿里云服务器发送邮件

阿里云服务器默认关闭25端口,只能使用465端口调用发送邮件

编辑配置文件

vim /etc/mail.rc  #以下内容在文件末尾添加
#set from=64688483@qq.com(彭于晏)  #设置发信人姓名和邮箱
set from=64688483@qq.com  #设置发信人邮箱
set smtp=smtps://smtp.qq.com:465    #邮件服务器
set smtp-auth-user=64688483@qq.com  #设置邮箱账号
set smtp-auth-password=ffboyhrr     #授权码或密码
set smtp-auth=login  #默认login
set nss-config-dir=/etc/pki/nssdb  #证书所在目录
set ssl-verify=ignore   #忽略证书警告

设置证书

cd /etc/pki/nssdb

获取证书文件

echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ./qq.crt

添加证书到证书数据库中

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

验证

[root@linux /]# cat x.txt 
Hello world
你好

[root@linux /]# cat x.txt|mail -s "test" 201448247@qq.com

Last modification:October 7, 2020
If you think my article is useful to you, please feel free to appreciate