一、准备条件
安装mail、formail、sendmail
二、发送邮件方式
2.1、cat report.html | /usr/bin/formail -I "From:xxx@xxx.com" -I "To:xxx@xxx.com" -I "Content-type:text/html;charset=gb2312" -I "Subject:ceshi" | /usr/sbin/sendmail -oi xxx@xxx.com
2.2、./sendmail.sh 接口测试 xxx@xxx.com report.html report.html
#!/bin/bash
#author:findyou
help(){
echo
"eg: $0 [Subject] [address] [content_file] [file]"
echo
""
exit
1
}
if
[ ! -n
"$1"
] ; then
help
fi
cDate=`date +%Y%m%d`
if
[ ! -n
"$2"
] ; then
help
else
mail_to=$
2
echo
" Send Mail to ${mail_to}"
fi
if
[ ! -n
"$4"
] ; then
mail -s $
1
${mail_to}<$
3
else
mail -s $
1
-a $
4
${mail_to}<$
3
fi
|
三、其他
3.1日志路径
/var/log/maillog
3.2启动sendmail
sudo chkconfig --levels 235 sendmail on
sudo service sendmail restart
四、其他方法【支持多附件,正文显示html】
# !/bin/sh
email_date=
''
email_subject=
'PHP_Base_Api自动化测试结果报告'
email_content=
"/root/jenkins/workspace/Robotframework_BasicInterface/result.html"
email_attach=
"/root/jenkins/workspace/Robotframework_BasicInterface/PHP_Base_Api/report.html /root/jenkins/workspace/Robotframework_BasicInterface/PHP_Base_Api/log.html"
function send_email(){
email_date=$(date
"+%Y-%m-%d_%H:%M:%S"
)
email_subject=$email_subject
"__"
$email_date
cat $email_content | /usr/bin/mutt -s $email_subject -a $email_attach -e
'set content_type="text/html"'
-e
'my_hdr from:'
$from -- $to
}
send_email
|