安装mailx:
#yum -y install mailx
编写/etc/mail.rc:
set bsdcompat
set from=simonwang@163.com
set smtp=smtp.163.com
set smtp-auth-user=simonwang@163.com
set smtp-auth-password=password
set smtp-auth=login
测试发送:
# cat /etc/fstab | mailx -v -s 'test' 'simonwang@163.com'
报错:
535 Error: authentication failed
554 DT:SPM
530 Error: A secure connection is requiered(such as ssl).
解决:
535:修改smtp-auth-password
554:发送的邮件内容包含了未被许可的信息,或被系统识别为垃圾邮件。请检查是否有用户发送病毒或者垃圾邮件
查了下原因,因为163反垃圾邮件设置的原因
530:添加参数
smtp-use-starttls
set ssl-verify=ignore
set nss-config-dir=/etc/pki/nssdb/
获取证书
mkdir -p /root/.certs/
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
成功:
>>> EHLO localhost
250-mail
250-PIPELINING
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UF05puqU
250-STARTTLS
250 8BITMIME
>>> AUTH LOGIN
334 dXNl5hbWU6
>>> MTU1MDU1NTjlAYzLmNvbQ==
334 UGFzc3dvc=mQ6
>>> cGFzc3dvcmQxN==
235 Authentication successful
>>> MAIL FROM:<simonwang@163.com>
250 Mail OK
>>> RCPT TO:<simonwang@163.com>
250 Mail OK
>>> DATA
354 End data with <CR><LF>.<CR><LF>
>>> .
250 Mail OK queued as smtp12,EMCowAC3Wm0QmpCMCA--.48584S2 1502525206
>>> QUIT
221 Bye
转载于:https://blog.51cto.com/echoroot/1955764