全局变量定义
USER="user"
PASSWORD="password"
SMTPSERVER="smtp.163.com:465"
MAILFROM="user@163.com"
MAILCC="test@desenpast.com"
MAILTO="desen@desenpast.com"
REALNAME="Desen往事"
ATTACH="/var/log/cron"
mutt 工具发送邮件
安装相关软件包
yum -y install mutt cyrus-sasl-plain
不加载 .muttrc 配置文件发送邮件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# 执行以下命令前请先定义全局变量 for NO in $(seq 1 1000) do echo "Test $NO" | \ mutt -s "Test $NO"\ -e "set smtp_url=smtps://${USER}@${SMTPSERVER}" \ -e "set smtp_pass=${PASSWORD}" \ -e "set smtp_authenticators=login:plain" \ -e "set charset=utf-8" \ -e "set send_charset=utf-8" \ -e "set ssl_force_tls=yes" \ -e "set from=${MAILFROM}" \ -e "set realname=${REALNAME}" \ -a "${ATTACH}" \ -c "${MAILCC}" \ -- ${MAILTO} grep -A 12 From ~/sent sleep 5 done |
mailx 工具发送邮件
创建新的证书目录, 查看并保存证书
mkdir ~/.certs
echo -n | openssl s_client -showcerts -connect ${SMTPSERVER} | \
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 ~/.certs/163.crt
certutil -L -d /root/.certs/
创建 .mailrc 用户环境配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 |
cat << EOF >> ~/.mailrc account 163 { set smtp=smtps://${SMTPSERVER} set smtp-auth-user=${MAILFROM} set smtp-auth-password=${PASSWORD} set smtp-auth=login set ssl-verify=ask set ssl-method=tls1 set nss-config-dir=/root/.certs/ set sendcharsets=utf-8 set from="${REALNAME} <${MAILFROM}>" } EOF |
更改 .mailrc 文件仅所有者可读
chmod 400 ~/.mailrc
加载 .mailrc 配置文件发送邮件
1 2 3 4 5 |
for NO in $(seq 1 1000) do echo "Test $NO" | mail -A 163 -v -s "Test $NO" -a "${ATTACH}" -c "${MAILCC}" ${MAILTO} sleep 5 done |
不加载 .mailrc 配置文件发送邮件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# 以下方式存在BUG, 邮件内容未包含中文时发送者中文名称会被省略 # 执行以下命令前请先定义全局变量 for NO in $(seq 1 1000) do echo "Test $NO" | \ mail -v -s "测试 $NO" \ -S smtp=smtps://${SMTPSERVER} \ -S smtp-auth-user=${MAILFROM} \ -S smtp-auth-password=${PASSWORD} \ -S smtp-auth=login \ -S ssl-verify=ask \ -S ssl-method=tls1 \ -S nss-config-dir=/root/.certs/ \ -S sendcharsets=utf-8 \ -S from="${REALNAME} <${MAILFROM}>" \ -a "${ATTACH}" \ -c "${MAILCC}" \ ${MAILTO} sleep 5 done |