How to send multiple attachments through e-mail in UNIX?

I am facing an issue with the “mailx” command while trying to mail attachments. I am able to mail a single attachment by using the “uuencode” command, I am not sure how to use it for multiple attachments…

PFA the sample code…

MESSAGE=$LOG_FILE or $ERR_FILE
FILE=$SOURCE_PATH/$ATTACHMENT_FILENAME
FILENAME=$ATTACHMENT_FILENAME’_’$DATE.csv
SUBJECT=’Last Run Details for the XYZ program’
MAILLIST=$SUCCESS_MAILLIST $ERROR_MAILLIST

For single file I am using:
(echo $MESSAGE; /bin/uuencode $FILE $FILENAME) | mailx -s “$SUBJECT” $MAILLIST
and have found it to be working fine…

But;
(echo $MESSAGE; /bin/uuencode $FILE $FILENAME $FILE1 $FILENAME1) | mailx -s “$SUBJECT” $MAILLIST
doesnt work…

Can someone please revert with a solution? Is it possible to send multiple attachments or do i have to resort to sending the mail twice or appending the attachments one after the other in a single file?

 

Yes, it is possible to send multiple attachment. You should sent multiple attachment like this(seperated with ;):

(uuencode $FILE $FILENAME; uuencode $FILE1 $FILENAME1; uuencode…….; uuencode $FILEn $FILENAMEn) | mailx -s “$SUBJECT” $MAILLIST

#!/bin/ksh
MESSAGE=$LOG_FILE or $ERR_FILE
SUBJECT=’Last Run Details for the XYZ program’
MAILLIST=$SUCCESS_MAILLIST
FILE1=$SOURCE_PATH/$ATTACHMENT_FILENAME.1; export FILE1
FILE2=$SOURCE_PATH/$ATTACHMENT_FILENAME.2; export FILE2
uuencode $FILE1 $ATTACHMENT_FILENAME.1 > tmpfile
uuencode $FILE2 $ATTACHMENT_FILENAME.2 >> tmpfile
echo $MESSAGE; cat tmpfile | mailx -m -s $SUBJECT $MAILLIST

Tags: , , , , , , , , , , , ,