yum install mailx -y
vi /etc/mail.rc //注意网易邮箱需要开启客户端授权码进行第三方登录
----文件末尾新增---
set bsdcompat
set from=wuyutang0219@163.com
set smtp=smtp.163.com
set smtp-auth-user=wuyutang0219@163.com
set smtp-auth-password=abc123
set smtp-auth=login
:wq
echo "hahahaha" | mail -s "testmail" wuyutang0219@163.com //测试发信正常
vi mailx.sh //编写发邮件脚本
#!/bin/bash
#send mail
messages=`echo $3 | tr '\r\n' '\n'`
subject=`echo $2 | tr '\r\n' '\n'`
echo "${messages}" | mail -s "${subject}" $1 >>/tmp/mailx.log 2>&1
touch /tmp/mailx.log
chown -R tang.tang /tmp/mailx.log
chmod +x mailx.sh
./mailx.sh wuyutang0219@163.com "主题" "内容" //测试发邮件脚本是否可以正常工作
使用465端口:阿里云新ECS默认关闭25端口。
set bsdcompat
set from=ytwu@leqee.com
set smtp="smtps://smtp.exmail.qq.com:465"
set smtp-auth-user=ytwu@leqee.com
set smtp-auth-password=********
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/etc/pki/nssdb
163邮箱:
set from="邮箱名"
set smtp="smtps://smtp.163.com:465"
set smtp-auth-user="邮箱名"
set smtp-auth-password="授权码"
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/etc/pki/nssdb
测试 :
echo ‘hello‘ |mail -v -s "test" 邮箱