linux下使用mail命令发送邮件

作者:邓聪聪

安装: yum install -y mailx

配置:

[root@95soft ~]# vi /etc/mailx 
set hold
set append
set ask
set crt
set dot
set keep
set emptybox
set indentprefix="> "
set quote
set sendcharsets=iso-8859-1,utf-8
set showname
set showto
set newmail=nopoll
set autocollapse
set markanswered
ignore received in-reply-to message-id references
ignore mime-version content-transfer-encoding
fwdretain subject date from to
set bsdcompat
# smtp服务器认证的用户名 
set from=mailuser
# smtp服务器的地址 
set smtp=smtp.qiye.aliyun.com
# 邮件认证的方式 
set smtp-auth=login 
# smtp服务器认证的用户名 
set smtp-auth-user=mailuser
# smtp服务器认证的用户密码(授权码) 
set smtp-auth-password=mailpassword
# 忽略验证 
set ssl-verify=ignore 
set nss-config-dir=/etc/maildbs/

ssl证书:

[root@95soft ~]# mkdir -p /root/.certs/
[root@95soft ~]# echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt
[root@95soft ~]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
[root@95soft ~]# certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
[root@95soft ~]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs/./ -i ~/.certs/163.crt
[root@95soft ~]# certutil -L -d /root/.certs

发信格式:

mail -s test admin@aispider.com #第一种方法,你可以把当前shell当成编辑器来用,编辑完内容后Ctrl-D结束

echo “mail content”|mail -s test admin@aispider.com #第二种方法,我用的最多,可能是喜欢管道的缘故吧

mail -s test admin@aispider.com< file #第三种方法,以file的内容为邮件内.容发信

mail -s test -c admin@aispider.com  root@aispider.com -a 附件< file #第四种方法,给多个用户发送邮件,带附件

 

posted @ 2019-11-27 20:11  邓聪聪  阅读(449)  评论(0编辑  收藏  举报