Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1279470
  • 博文数量: 168
  • 博客积分: 3483
  • 博客等级: 中校
  • 技术积分: 1696
  • 用 户 组: 普通用户
  • 注册时间: 2006-02-06 13:17
文章分类

全部博文(168)

文章存档

2015年(6)

2014年(9)

2013年(47)

2012年(11)

2011年(13)

2010年(18)

2009年(11)

2008年(42)

2007年(11)

分类: LINUX

2013-08-31 14:39:00


点击(此处)折叠或打开

  1. #!/bin/sh
    #       filename: msmtp_send
    #       Copyright 2010 wkt
    # modified by yinjianhong, used for send review request mail.
    # modified by jiali, add option for cc|to
    # modified by yinjianhong, add comment. and if patch is empty not send.

    Usage() {
            echo Usage:
            echo -e "\t${0##*/} [-c \$cc@x.com] [-t \$to@x.com] [object]"
            exit ${1:-1}
    }

    TEMP=`getopt -o "::c:t:" --long target   -n 'example.bash' -- "$@"`
    if [ $? != 0 ] ; then Usage >&2 ; exit 1 ; fi

    # Note the quotes around `$TEMP': they are essential!
    eval set -- "$TEMP"
    #===============================================================================
    # parse the argument
    OPTIND=1
    while true ; do
            case $1 in
            -t)     to="$2 $to"; shift 2;;
            -c)     cc="$2 $cc"; shift 2;;
            --)     shift; break;;
            *) echo "Internal error!"; exit 1;;
            esac
    done
    [ $# -lt 1 ] && Usage

    fpatch=$1
    shift
    disc=$@

  2. #===============================================================================
  3. mode=$(git remote -v 2>/dev/null|awk '$3=="(fetch)"{print gensub(".*/","",1,$2)}')
  4. # you should need custmize the follow default value:
  5. to=${to:-fs-qe-dev@RH.com}
  6. cc=${cc:-kxz@RH.com}
  7. disc="$mode: ${disc}" #subject discriptioan,
  8. prefix=${prefix:-[code review] }
  9. from=`git config user.email 2>/dev/null`

  10. #===============================================================================
  11. # the config file of smtp
  12. smtp_server=smtp.corp.RH.com
  13. rc=$(mktemp /tmp/.mailrc.XXXXXXXX)
  14. cat <<___eof_ > ${rc}
  15. defaults
  16. #keepbcc on

  17. ###QQ邮箱不支持tls,使用QQ邮箱需要关闭tls_starttls
  18. #tls_starttls off
  19. #tls on

  20. ###网易免费企业邮箱的ssl证书通不过验证,所以使用 网易免费企业邮箱 时,只能关闭tls证书验证
  21. #tls_certcheck off

  22. #使用 网易免费企业邮箱 时,需要注释掉tls_trust_file
  23. #tls_trust_file /usr/lib/ssl/certs/ca-certificates.crt

  24. ##可以在这里填写邮箱密码,当然这样不是很安全
  25. #password my_password

  26. #auth on
  27. tls_certcheck off
  28. syslog on

  29. account rh
  30. host $smtp_server
  31. from $from
  32. user $from

  33. #设置默认msmtp使用的账号信息
  34. account default : rh
  35. ___eof_

  36. #更改配置文件权限,权限不对mstp拒绝干活
  37. chmod og-rwx $rc

  38. #===============================================================================
  39. # proccess the mail file and send.
  40. tm=$(mktemp /tmp/.mail.XXXXXXXX)
  41. [ "$fpatch" = ? ] && Usage 0

  42. [ "$fpatch" = - ] && {
  43.     while read -r l; do echo "$l"; done >$tm
  44.     fpatch=$tm
  45. }
  46. [ "$fpatch" = + ] && {
  47.     [ -z "$cc" ] && {
  48.         echo -n "input the 'to' addr list: "
  49.         read to; }
  50.     [ -z "$to" ] && {
  51.         echo -n "input the 'cc' addr list: "
  52.         read cc; }
  53.     disc="${disc#nfs-utils: }"
  54.     prefix=''

  55.     fpatch=$tm
  56.     vim $fpatch
  57. }
  58. grep -q '[^ \t]' $fpatch || {
  59.     echo "warn: empty mail file. exit no send.";
  60.     exit 1;
  61. }

  62. #to=$from; cc=$from
  63. send() {
  64.     echo "sending ..."
  65.     cat <<-__mail_ |msmtp -C $rc $to
  66.     TO:$to
  67.     FROM:$from
  68.     CC:$cc
  69.     SUBJECT: $prefix${disc}

  70.     $(cat $fpatch)

  71.                                                                         # ~RH~
  72.     __mail_
  73. }

  74. send
  75. rm -f ${rc} ${tm}

阅读(1555) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~