Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to send single attachments using sendmail

Shell Scripts

Script to send single attachments using sendmail

by  aixmurderer  Posted    (Edited  )
Some modifications may be needed for your needs. Note, it doesn't support anything else but a .txt based attachment.

#!/bin/ksh
: '
sendattch.sh : Encapsulate standard input as a MIME attachment
and mail it to the correct destination.

ARGS: 1: Delivery address
2: File to send as attachment
'
ADDR=$1
FILE=$2
INTCHG=`basename $2 .txt`

USAGE="Usage: sendattch.sh delivery_address file_name"

TEMP=/tmp/$INTCHG.att

# Tidy-up Function

function doExit {
rm -f $TEMP
exit $1
}

# Validate arguments

[[ $# -eq 2 ]] || {
echo "Invalid number of arguments: $#\n$USAGE" >&2
doExit -1
}

# Construct the message

{
echo "To: $ADDR"
echo "Subject: $INTCHG"
echo "X-Priority: 3"
echo "MIME-Version: 1.0"
echo "Content-Type: application/msword;"
echo " name=\"$INTCHG.txt\""
echo "Content-Disposition: attachment;"
echo " filename=\"$INTCHG.txt\""
echo "Content-Description: $INTCHG"
echo
cat $FILE
} > $TEMP

# Send the constructed message

/usr/sbin/sendmail $ADDR < $TEMP
doExit $?
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top