Sections
JMail - Sending mail with attachment
Presentation
-
This script is the equivalent to mailx command, but offers the possibility to send files as attachments to the message.
Here is the syntax:
-
jmail -s "Mail subject" [-sender sender_email] [-html] [-cc email_copy] [-j file_to_attach] recipient_email
-html option to send the mail in html format
-cc option to add people in copy of the mail
The script
#!/bin/ksh # Version 1.00 - 09/07/2000 # Auteur: Jerome DESMOULINS USAGE="Usage: $0 [-s 'Subject'] [-sender email_of_sender] [-html] [-cc E-mail] [[-j File] ...] E-mail [[E-mail] ...]" Mail_hub=`hostname ` Mail_user=$LOGNAME Boundary_mark="GM_Fecit" Subject="De `uname -n | cut -d'.' -f1`" Sender_address="$Mail_user@$Mail_hub" Format="text" export TERM=vt100 # Analyse des parametres while [ "$*" != "" ]; do case $1 in "-s") Subject=$2; shift 2;; "-sender") Sender_address=$2; shift 2;; "-j") [ -r $2 ] || { echo "$0: Ne peut lire $2"; exit 1; } File_lst="$File_lst $2"; shift 2;; "-html") Format="html"; shift;; "-cc") Mail_cc="$Mail_cc $2"; shift; shift;; *@*) Mail_lst="$Mail_lst $1"; shift;; esac done [ -z "$Mail_lst" ] && { echo "$USAGE\r You must specify at least one !"; exit 1; } ( sleep 1 echo "HELO $Mail_hub"; if test $Sender_address = "$Mail_user@$Mail_hub" then echo "MAIL FROM: <$Mail_user@$Mail_hub>"; sleep 1 else echo "MAIL FROM: <$Sender_address>"; sleep 1 fi for MailAddress in $Mail_lst; do echo "RCPT TO: <$MailAddress>"; done echo "DATA"; sleep 1 if test $Sender_address = "$Mail_user@$Mail_hub" then echo "From: $Mail_user@$Mail_hub ($0)" else echo "From: $Sender_address ($0)" fi echo "Subject: $Subject" echo "To: `echo $Mail_lst| tr ' ' ';'`" echo "Cc: `echo $Mail_cc| tr ' ' ';'`" echo "Date: `date `" echo "MIME-Version: 1.0" echo "X-Mailer: $0" echo "Content-Type: multipart/mixed; boundary=\"$Boundary_mark\"" echo echo "--$Boundary_mark" echo "Content-Type: text/$Format" echo "" # Le message cat <&0 | sed -e 's/^\.$/\.\./' echo "\n\n\n" # Les pieces jointes for File in $File_lst; do File_name=`basename $File` echo "--$Boundary_mark" echo "Content-Type: text/plain; name=\"$File_name\"" echo "Content-Disposition: attachment; filename=\"$File_name\"" echo "" cat $File | sed -e 's/^\.$/\.\./' echo "--$Boundary_mark" done echo "."; sleep 1 echo "QUIT"; sleep 1 echo "O\003" ) | telnet $Mail_hub 25 > /dev/null 2>&1 exit 0Go back