Admin/pmail
author isatest
Tue Jul 09 11:46:36 2002 +0200 (2002-07-09)
changeset 13320 2c6ee189ae63
child 13321 70a5d5fc081a
permissions -rwxr-xr-x
send email plaform independently
isatest@13320
     1
#!/usr/bin/env bash
isatest@13320
     2
#
isatest@13320
     3
# $Id$
isatest@13320
     4
# Author: Gerwin Klein, TU Muenchen
isatest@13320
     5
# License: GPL (GNU GENERAL PUBLIC LICENSE)
isatest@13320
     6
#
isatest@13320
     7
# DESCRIPTION: send email platform independently.
isatest@13320
     8
isatest@13320
     9
PRG="$(basename "$0")"
isatest@13320
    10
isatest@13320
    11
function usage()
isatest@13320
    12
{
isatest@13320
    13
  echo
isatest@13320
    14
  echo "Usage: $PRG subject recipient body"
isatest@13320
    15
  echo
isatest@13320
    16
  echo "  Send email platform independently. Body is a file."
isatest@13320
    17
  echo
isatest@13320
    18
  exit 1
isatest@13320
    19
}
isatest@13320
    20
isatest@13320
    21
function fail()
isatest@13320
    22
{
isatest@13320
    23
  echo "$1" >&2
isatest@13320
    24
  exit 2
isatest@13320
    25
}
isatest@13320
    26
isatest@13320
    27
## main
isatest@13320
    28
isatest@13320
    29
# argument checking
isatest@13320
    30
isatest@13320
    31
[ "$1" = "-?" ] && usage
isatest@13320
    32
[ "$#" != "3" ] && usage
isatest@13320
    33
isatest@13320
    34
SUBJECT=$1
isatest@13320
    35
TO=$2
isatest@13320
    36
BODY=$3
isatest@13320
    37
isatest@13320
    38
[ -r $BODY ] || fail "could not read $BODY"
isatest@13320
    39
isatest@13320
    40
case `uname` in
isatest@13320
    41
    Linux*)
isatest@13320
    42
    mail -s "$SUBJECT" $TO <$BODY
isatest@13320
    43
    ;;
isatest@13320
    44
isatest@13320
    45
    SunOS*)
isatest@13320
    46
    mail -t $TO <<EOF
isatest@13320
    47
Subject: $SUBJECT
isatest@13320
    48
isatest@13320
    49
`cat $BODY`
isatest@13320
    50
EOF
isatest@13320
    51
    ;;
isatest@13320
    52
isatest@13320
    53
    *)  
isatest@13320
    54
    fail "unkown platform"
isatest@13320
    55
    ;;
isatest@13320
    56
esac