"multiple attachments"

Post #33234 by Perderabo on Friday 20th of December 2002 12:58:36 PM

Full Discussion: multiple attachments
mimesender -- part two

Code:
		if ((nattach)) ; then
			DESC[nattach-1]=$OPTARG
		else
			scribe_err -D $optarg must follow a -A argument
			((error=error+1))
		fi
		;;
	s)
		SUBJECT=$OPTARG
		;;
	\?)
		scribe_err what is -${OPTARG}?
		((error=error+1))
		;;
	:)
		scribe_err $OPTARG need an argument
		((error=error+1))
		;;
	esac
done

#
#  Parameter error checking: an address is required

if ((!naddr)) ; then
	scribe_err "-t ADDRESS is required"
	((error=error+1))
fi


#
#  Parameter error checking: If BODY  was specified, it
#  must exist and be readable

if [[ ! -z $BODY ]] ; then
	if [[ $BODY != - ]] ; then
		if [[ ! -f $BODY ||  ! -r $BODY ]] ; then
			scribe_err  "-b $BODY is not a readable file"
			((error=error+1))
		fi
	else
		stdin_inuse=1
	fi
fi

#
#  Parameter error checking: If ATTACH was specified, it
#  must exist and be readable.  
#  Also we can use stdin only once

i=0
while ((i<nattach)); do
	if [[ ${ATTACH[i]} = - ]] ; then
		if ((stdin_inuse)) ; then
			scribe_err  only one item may come from stdin
			((errors=errors+1))
		else
			stdin_inuse=1
		fi
	else
		if [[ ! -f ${ATTACH[i]} ||  ! -r ${ATTACH[i]} ]] ; then
			scribe_err  -A ${ATTACH[i]} is not a readable file
			((error=error+1))
		fi
	((i=i+1))
	fi
done

#
#  FADDR must not have a @ in it.

if [[ $FADDR = *@* ]] ; then
	scribe_err You cannot specify a remote \"From:\" address
	((error=error+1))
fi

#
# We will abort now if we didn't like our parameters

if ((error)) ; then
	scribe_err "at least one fatal error was detected...exiting"
	exit 1
fi



#############################################################
#                                                           #
#    Section 2 ---  Build Header, Preamble, and Body        #
#                                                           #
#############################################################

#
#  Get user's name and address from the system


scribe_debug pwentry = $pwentry
if [[ $this_shell = ksh ]] ; then
	((index=0))
	while [[ $pwentry = *:* ]] ; do
		pwfield[index]=${pwentry%%${pwentry##*([!:])}}
		pwentry=${pwentry##*([!:]):}
		((index=index+1))
	done
	pwfield[index]=${pwentry}
	myname=${pwfield[4]%%,*}
	myaddr=${pwfield[0]}
else
	myaddr=$(echo "$pwentry" | sed 's/\([^:]*\).*$/\1/')
	myname=$(echo "$pwentry" | \
			sed 's/[^:]*:[^:]*:[^:]*:[^:]*:\([^,:]*\).*$/\1/')
fi

scribe_debug myaddr = $myaddr
scribe_debug myname = $myname


#
# NB the following brace.  It is the start of the stuff piped to the MTA

{

#
#  Start with the "From:" Address

if [[ -n $FADDR ]] ; then
	if [[ -n $FNAME ]] ; then
		scribe_out "From: $FNAME <${FADDR}>"
	else
		scribe_out "From: $myname <${FADDR}>"
	fi
	scribe_out  "Sender: $myname <${myaddr}>"
elif [[ -n $FNAME ]] ; then
	scribe_out "From: $FNAME <${myaddr}>"
else
	scribe_out  "From: $myname <${myaddr}>"
fi

#
#  Next we will do the "To:" Addresses

((i=0))
Line=""
while ((i<naddr)) ; do
	if [[ -n ${TNAME[i]} ]] ; then
		Addition="${TNAME[i]} <${TADDR[i]}>"
	else
		Addition="${TADDR[i]}"
	fi

	if [[ -n $Line &&  $((${#Line}+${#Addition})) -gt 75 ]] ; then
		scribe_out "$Line"
		Line=""
	fi

	if [[ -z $Line ]] ; then
		Line="To: $Addition"
	else
		Line="$Line, $Addition"
	fi
	((i=i+1))
done
scribe_out "$Line"

#
#  Some misc header lines

if [[ -n $SUBJECT ]] ; then
	scribe_out  'Subject:' $SUBJECT
fi
scribe_out  'X-Mailer: mimesender' $VERSION
scribe_out  'Mime-Version: 1.0'

#
#  Output Mime Preamble if there are multiple parts

if ((npart>1)) ; then
	scribe_out  'Content-Type: multipart/mixed; '
	scribe_out  '    boundary='\"$BOUNDARY\"
	scribe_out 
	scribe_out  "$PREAMBLE"
	scribe_out 
fi

#
#  Output message body if we have one.

if [[ -n $BODY ]] ; then
	if ((npart>1)) ; then
		scribe_out  "--${BOUNDARY}"
	fi
	scribe_out  'Content-Type: text/plain; charset=US-ASCII'
	scribe_out 
	if [[ $BODY = - ]] ; then
		cat
	else
		cat $BODY
	fi
else
	scribe_out
fi

#############################################################
#                                                           #
#    Section 3 ---  Attachments                             #
#                                                           #
#############################################################
#

#
#  Loop on our attachments... 

i=0
while ((i<nattach)) ; do
	scribe_debug Attachment $i ${ATTACH[i]} ${FORMAT[i]} ${DESC[i]}

#
#  If we are in mutipart mode, do a boundary

	if ((npart>1)) ; then
		scribe_out  "--${BOUNDARY}"
	fi

#
#  Build attachment header

	if [[ ${FORMAT[i]} = B ]] ; then
		TYPE=$BType
	else
		TYPE=$AType
	fi
	scribe_out  'Content-Type: '${TYPE}'; name="'${ATTACH[i]}\"

	if [[ ${FORMAT[i]} != A ]] ; then
		scribe_out "Content-Transfer-Encoding: x-uue"
	fi

	scribe_out  'Content-Disposition: attachment; filename="'${DESC[i]}\"
	scribe_out 

#
#  Build a pipeline to process the attachment

	if [[ ${ATTACH[i]} = - ]] ; then
		PIPELINE="cat"
	else
		PIPELINE="cat ${ATTACH[i]}"
	fi
	[[ ${FORMAT[i]} = X ]] && PIPELINE=${PIPELINE}"| sed \"s/$/\${CR}/\""
	[[ ${FORMAT[i]} != A ]] && PIPELINE=${PIPELINE}"|uuencode ${DESC[i]}"
	scribe_debug PIPELINE = "$PIPELINE"
	eval $PIPELINE

	scribe_out 
	((i=i+1))
done

#############################################################
#                                                           #
#    Section 4 ---  Send Mail                               #
#                                                           #
#############################################################
#

#
#  If in multipart mode, do final boundary

if ((npart>1)) ; then
	scribe_out  "--${BOUNDARY}--"
fi

#
#  Here is where we send the mail

} | eval $MTA ${TADDR[@]}

if ((DEBUG)) ; then
	while read l ; do scribe_debug "$l" ; done < $DEBUGFILE
	rm $DEBUGFILE
fi

exit 0

These 2 Users Gave Thanks to Perderabo For This Post:
 
Test Your Knowledge in Computers #51
Difficulty: Easy
The term 'IoT' means the 'Internet of Tomorrow'.
True or False?

10 More Discussions You Might Find Interesting

1. How do I send email?

multiple attachments

how can you send multiple attachments in 1 email, usually I just use uuencode to send 1 attachment. thanks (5 Replies)
Discussion started by: edog
5 Replies

2. Shell Programming and Scripting

Sending multiple attachments

Hi people, I am new to this forums. I have a quick question I hope one of you could help me with. I am writing a script to send attachments via email. However I am having trouble when trying to send multiple attachments. Here is the code I am using: send_mail() { uuencode $TMP $TMP1 > $TMP1... (1 Reply)
Discussion started by: deo2k8
1 Replies

3. Shell Programming and Scripting

e-mail with multiple binary attachments!

Hi, I have to send email from UNIX with multiple excel attachments and the sender name needs to be customized (sender name need not to be UNIX user). I have checked many ways from this forum and other sources. But, nothing did work for me. Please help me! thanks, Raja. (1 Reply)
Discussion started by: smr_rashmy
1 Replies

4. Shell Programming and Scripting

E-mailing Multiple Attachments in AIX

Hello Everyone, I'm trying to write ascript on AIX 5.3, that will e-mail all filles within a directory. But on executing a script , it sends only 1 file from the directory alongwith some Junk data. I have searched whole forum and almost used all the suggestions, but still getting same problem.... (4 Replies)
Discussion started by: Gem_In_I
4 Replies

5. Shell Programming and Scripting

Problem with multiple mail attachments

Hi everyone... I am facing problem with the multiple mail attachments. cd /work/mohan/pi_log/ mail_file='uuencode ahmedabad.csv ahmedabad.csv ; uuencode ahmedabad_devrpt_20110530.csv ahmedabad_devrpt_20110530.csv' ( $mail_file ) | mailx -m -s"test" domain@website.com its giving me error... (1 Reply)
Discussion started by: mohanm
1 Replies

6. Shell Programming and Scripting

Sending Multiple Attachments using MAILX

I have created a shell scripts and wanted to email users multiple attachments using mailx. I noticed that when I do a man on mailx I see and -a option for attachments. When I run a: mailx -s "test attachments" -a include_file -a exclude_file testuser@mydomain.com (Interrupt -- one more to... (1 Reply)
Discussion started by: metallica1973
1 Replies

7. Shell Programming and Scripting

How to send email with multiple attachments ?

Hello , I am trying to send an email with two attachments . I have tried all previous suggestion in this forum but none worked. I could send one attachment in an email by uuencode $file "$file" | mailx -m -s "File" xxx@xx.com but unable to send multiple attachments . I have tried ... (8 Replies)
Discussion started by: RaviTej
8 Replies

8. Shell Programming and Scripting

Multiple attachments using mutt

I am trying to attach multiple files using mutt command, and all file names to be attached are taken from a flat file. and mutt command is called from a bash script when : 1. Script execution is completed. 2. Script execution is interrupted for some reason. ... (8 Replies)
Discussion started by: Shaishav Shah
8 Replies

9. Red Hat

How to send mail with multiple attachments?

We don't have uuencode installed in our machines..... Please tell me how to send mail with multiple attachments ??? URGENT !!!!! Please tell me using command line (or) scripts.......... please...... Thanks in Advance.... (1 Reply)
Discussion started by: vamshigvk475
1 Replies

10. HP-UX

Email Using uuenview w/ Multiple Attachments

HP-UX mbhp7640 B.11.31 U ia64 4294967295 unlimited-user license Our database builds a MIME compliant html email, then cats that to sendmail - no problem. Due to horrible issues with the native uuencode, we long ago began using uuenview to encode our attachments - no problem. An example is... (1 Reply)
Discussion started by: bubba77
1 Replies

Featured Tech Videos

All times are GMT -4. The time now is 03:16 PM.
Unix & Linux Forums Content Copyright 1993-2019. All Rights Reserved.
Privacy Policy