系统自带的是postfix邮件服务,postmail的命令行是sendmail命令,这里需要注意的是和sendmail服务名字一样,但是是完全不一样的东西。
yum -y install sendmail mailx
这里的mailx是客户端,有了它更容易发送邮件。
启动sendmail服务
systemctl start sendmail
sendmail服务监听的是25端口,所以需要开放25端口
mail -v -s "subject_title" root < /etc/passwd
mail -v -s "subject_title" niu < /etc/passwd
set from=complet@163.com
set smtp=smtp.163.com
set smtp-auth-user=用户名
set smtp-auth-password=授权码
set smtp-auth=login
以上这个配置是需要服务器开启25端口,才能发送成功。
set from=邮箱地址
set smtp=smtps://smtp.163.com:465
set ssl-verify=ignore
set nss-config-dir=/root/.certs
set smtp-auth-user=邮箱用户名
set smtp-auth-password=smtp授权密码
set smtp-auth=login
需要导入证书
mkdir /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 Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
certutil -L -d /root/.certs
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs/ -i ~/.certs/163.crt
echo "hello mymail.com" | mail -v -s "Title" telegram:@tianmeiapp@qq.com
tail /var/log/maillog
1、通过文件内容发送
发送命令:mail -s 'mail test' xxx@yyy.com < con.txt ("mail test"为邮件主题,xxx@yyy.com为收件人邮箱,con.txt保存邮件内容)
2、通过管道符直接发送
发送命令:echo "this is my test mail" | mail -s 'mail test' xxx@yyy.com
原文链接:centos7邮件服务sendmail使用说明,转载请注明来源!