Linux.com

Home Linux Community Forums Software Productivity auto print email attachments as they arrive

auto print email attachments as they arrive

Link to this post 30 Jan 11

I now added an eMail-Response in case of failure to print.
This needs a working mail command.

#!/bin/bash
SUPPORTED_FILETYPES=".pdf.jpg.png.tif.gif"
LP_OPTIONS="-o media=A4,tray1 -o fit-to-page -o position=top -o scaling=100"

MAILFILE=~/mailtemp/$(date +%H%M%S).txt
PRINT_FOLDER=~/printable

/usr/bin/fetchmail --bsmtp $MAILFILE

if [ "$?" = "0" ]; then
MAIL_ADDRESS=$(grep 'From:' $MAILFILE | sed -n -e 's/^[^<]*<\([^>]*\)>.*$/\1/p')
/usr/bin/uudeview +e $SUPPORTED_FILETYPES -p $PRINT_FOLDER -i $MAILFILE
rm $MAILFILE

PRINTED="no"

for f in $PRINT_FOLDER/*
do
if [ "$f" != "$PRINT_FOLDER/*" ]; then
LP_OUTPUT=$(lp $LP_OPTIONS $f)
if [ "$?" != "0" ]; then
MAILTEXT="File $f could not be printed."
echo "$MAILTEXT" | mail -s "Print-Error" $MAIL_ADDRESS
fi
rm $f
PRINTED="yes"
else
if [ "$PRINTED" = "no" ]; then
echo "No printable Attachments" | mail -s "Print-Error" $MAIL_ADDRESS
fi
fi
done
~/mailprint
fi

For that to work, you have to add the following line to your .fetchmailrc:

fetchlimit 1

With this line, only one mail is received each time the script is executed.
Therefore the script calls itself again as long as messages are downloaded.

Link to this post 30 Jan 11

Thanks a lot for your help - I have had an other problem unrelated to this one that would love to have solved dont know if its up your ally so to speak http://www.linux.com/community/forums?func=view&catid=22&id=9161

any ideas ?

Link to this post 31 Jan 11

I fear, that is not my cup of tea...

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board