linux发送邮件相关

一、准备条件

安装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
from= 'xxx@xxx.com'
to= 'xxx@xxx.com'
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

五、指定发件人地址

指定发件人邮箱信息命令:vi /etc/mail.rc,编辑内容在底部添加如:

set from=san.zhang @xxx .com smtp= "192.168.xx.xx"
set smtp-auth-user= "san.zhang" smtp-auth-password= "password"
set smtp-auth=login

六、简易命令

cat xx.log | mail -s 'test' -a xxx.log xx@xx.com

-s 标题

-a 附件

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值