TransWikia.com

Attachments are missing when multiple files are attached in mail

Unix & Linux Asked by Aravind on December 3, 2020

I have written one script to get multiple attachments through mail. My script is

for file in `find $dir -ctime -2 -type f -name "Sum*pdf*"`
do
echo "$file"
filename=`basename $file`
echo $filename -exec uuencode {} {};|mailx -s "North" [email protected]
echo "$filename"
done

But I am getting mail without attachments. Please help me what is wrong in this.

3 Answers

The use of uuencode is not standard and won't give you attachments. If you want to send a mail with multiple attachments, the easiest solution may be to use Mutt with mutt -s subject -a file1 file2 ... filen -- address < message

Answered by vinc17 on December 3, 2020

Here, use this :).

#!/bin/bash
RECIP="[email protected]"
SRCDIR="yourdirectory"
TMPDIR="tmp"
[ ! -d "$TMPDIR" ] && mkdir -p "$TMPDIR"

attargs=""
for file in `find "$SRCDIR" -ctime -2 -type f -name "Sum*pdf*"`; do
    echo "$file" #DEBUG
    filename=`basename $file`
    uuencode "$file" "$filename" > "$TMPDIR/${filename}"
    attargs="${attargs} -a $TMPDIR/$filename"
done

echo "mailx -s "Done" ${attargs[@]} $RECIP" #DEBUG
echo | mailx -s "Done" ${attargs[@]} "$RECIP"

Afterwards delete the temporary dir, which contains all the uuencoded files.

Make sure you decode them with uudecode.

Answered by polym on December 3, 2020

I found this tip that shows how to use uuencode to append multiple attachments to a single file, and then attach this single file to the email. The article is titled: Email Multiple File Attachments From Solairs / AIX / HP-UX / UNIX / Linux Command Line.

Example

$ uuencode r1.tar.gz r1.tar.gz > /tmp/out.mail
$ uuencode r2.tar.gz r3.tar.gz >> /tmp/out.mail
$ uuencode r3.tar.gz r3.tar.gz >> /tmp/out.mail
$ cat email-body.txt >> /tmp/out.mail
$ mail -s "Reports" [email protected] < /tmp/out.mail

Answered by slm on December 3, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP