Monday, 6 October 2014

Shell Script : Mail Attachment Linux uuencode

This example shows how to send an email with multiple attachments in linux using uuencode and mail command.

Files to be attached -

/opt/file1.txt
/opt/file2.txt
/opt/file3.txt
/opt/file4.txt

Code -

#/bin/bash

>/tmp/out.mail

echo "Your messae body" >> /tmp/out.mail

for i in `ls /opt/file*.txt`
do
uuencode  $i $i  >> /tmp/out.mail

done

mail -s "Subject" emailid@domain.com < /tmp/out.mail

#######

[ Note - If you've files having different names like abcd.txt outfile.txt sample.csv etc. then you can define the 'for' loop like - for i  in  abcd.txt outfile.txt sample.csv and while uuencode give the full path ]


If you have any queries or suggestions , please comment.



Thanks

No comments:

Post a Comment