Centos7下使用mail发送邮件
Centos7下使用mail发送邮件
- 首先检测相关服务是否已安装
[[email protected] ~]# rpm -qa|grep mail
libreport-plugin-mailx-2.0.9-19.el6.x86_64
mailx-12.4-7.el6.x86_64
procmail-3.22-25.1.el6.x86_64
mailcap-2.1.31-2.el6.noarch
sendmail-8.14.4-8.el6.x86_64
- 若服务未安,则执行以下命令进行服务安装
[[email protected] ~]# yum install sendmail
[[email protected] ~]# yum install mailx –y
[[email protected] ~]# yum update libreport-plugin-mailx
[[email protected] ~]# yum -y install sharutils
[[email protected] ~]# yum install mutt
- 修改配置文件,配置邮件相关内容(追加到配置文件末尾)
[[email protected] ~]# vi /etc/mail.rc
set [email protected] #之前设置好的邮箱地址
set smtp=smtp.163.com #邮件服务器
set [email protected] #之前设置好的邮箱地址
set smtp-auth-password=lvyf0802 #授权码
set smtp-auth=login #默认login
- 邮箱开启smtp服务(这里以163邮箱为例)
- 检测服务是否安装成功
[[email protected] ~]# touch /usr/mail.txt
[[email protected] ~]# mail -s "theme" [email protected] < /usr/mail.txt
//使用上面的命令就可把mail.txt文件的内容发给 [email protected](-s “theme” 为邮件的主题)
- 为了防止垃圾邮件泛滥,阿里云服务器已不再开放smtp邮件的25端口,现在需要使用465端口进行smtp邮件发送。
- 生成**
[[email protected] ~]mkdir -p /root/.certs/
echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs/./ -i 163.crt
certutil -L -d /root/.certs
2.配置**(红色代表修改内容)
[[email protected] ~]# vi /etc/mail.rc
set bsdcompat
set [email protected] #之前设置好的邮箱地址
set smtp=smtps://smtp.163.com #邮件服务器
set [email protected] #之前设置好的邮箱地址
set smtp-auth-password=lvyf0802 #授权码
set smtp-auth=login #默认login
set ssl-verify=ignore #ssl认证方式
set nss-config-dir=/root/.certs #证书所在目录