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 09 Sep 10

Here are the responses I received so far, I don't think these people want to join a forum, but they agreed to allow me to repost their information.

James
At one time I had a php script that automatically printed any emails sent to z special address. It would actually be easy to adapt it to attachments. I'll look through my backups and see if I can change it. If I did maybe someone could concert.

Henry
The guy wants his email PDF attachments automatically printed. I do similar
things at work.

1. Set up procmail. I do this the old way, by creating a ~/.forward file
containing

"|exec /usr/bin/procmail"

2. Set up a procmail rule in ~/.procmailrc for his emails. It sounds like they
are all coming from one email address, so that would make it really easy. If
they are coming from multiple addresses, then you could still create a
procmail rule based on the To address (and using a special address to receive
the fax on), or specifying a specific subject line. Assuming one from address,
you would have a procmail rule like this:

:0
* ^From:.*myvoip@myvoipdomain.com
| "/home/myname/bin/handle_pdf_att"

3. Create program to process the emails - ~/bin/handle_pdf_att. At this point,
most people say "it's Linux, write your own". I wrote a Perl program that
accepts the emails via stdin, and processes them. Initially I used the Perl
email and MIME libraries from CPAN, but they really sucked, and when I needed
some more detailed mail handling, I found too many of them said things like
"not implemented yet" or "author stopped here and then disappeared, someone
needs to finish this stuff". I wrote my own Perl module to parse the emails,
extract attachments, decode them, etc. Very direct, not fancy, did precisely
what I needed and no more. Not worth passing back to CPAN, not generic enough.
But good enough to handle all incoming email for several domains for several
years without needing attention. If your user wanted, I could easily produce a
new Perl program to extract PDFs from the emails, decode them, write them to
disk so he has permanent storage of them, and then print them. It would take a
few hours. I would be happy to do this.

Henry
Henry wrote:
> 1. Set up procmail. I do this the old way, by creating a ~/.forward file
> 2. Set up a procmail rule in ~/.procmailrc for his emails. It sounds like they
> 3. Create program to process the emails - ~/bin/handle_pdf_att. At this point,

This would only work if the user was using a traditional email system on his
Linux box. One where there is an MTA on the box (sendmail, postfix, qmail,
etc) and his MUA (pine, mutt, etc) pulled from it. And fetchmail pulled from
the ISP and handed email to the MTA. I think that is not common today.

If they have an MUA like Thunderbird that pulls directly from an ISP,
eliminating the need for having an MTA on the box, then my suggested approach
will not work. And I think that this is the more usual way that Linux boxes
are set up these days.

I will post additional responses as they arrive or relay additional questions that you have for the responders.

Link to this post 10 Sep 10

thanks for the input -

I was wondering , this claws email has actions and commands that can be added in the gui, but I dont understand how that all works.

anyway any suggestions will be tried and tested to the best of my abilities

Cheers

Link to this post 11 Sep 10

Must it be with claws email or can you use another mail client?

Link to this post 11 Sep 10

No anything that will work will be great - http://www.linux.com/components/com_kunena/template/default/images/english/emoticons/smile.png

the ultimate solution is a set-up would be

1. email is checked every say 2 minutes

2. emails that have just arrived get downloaded

2. emails with an attachment get there attachment printed forthwith

It would be best if this worked in the background and ran 24 / 7 and restarted its self even if the computer restarted

Link to this post 20 Jan 11

Hi,

I see this post was inactive for some time and I hope my answer will still help.

I just set up exactly what you are trying to do.

Programs needed:
[ul][li]fetchmail[/li][li]uudeview[/li][li]cups[/li][/ul]
I created a user named "autoprint" for this task

First you need to set up fetchmail to retrieve mail from your account and save it to a file.
In the users home directory create file .fetchmailrc and do chmod 600 on it (fetchmail will issue a warning if other users have read privileges on this file)

it should have following content:

poll your.mailserver.xx
proto POP3
user your-mailbox-username
pass secretpassword

for proto you should also be able to use IMAP.

now you just need a shell script to download mail and print it:


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

FILENAME=$(date +%H%M%S).txt

/usr/bin/fetchmail --bsmtp ~/mailtemp/$FILENAME

if [ "$?" = "0" ]; then
/usr/bin/uudeview +e $SUPPORTED_FILETYPES -p ~/printable -i ~/mailtemp/$FILENAME
rm ~/mailtemp/$FILENAME

for f in ~/printable/*
do
lp $LP_OPTIONS $f
rm $f
done
fi

The script does the following:
[ul][li]save the mail to a file naed by the current time - just in case two files exist at the same time which should not happen[/li][li]If mail has been retrieved, pass the file to uudeview and extract all attachments with the extensions listet in FILETYPES. Which files are supported by cups, you can find with google. uudeview also accepts multiple emails in one file[/li][li]The extracted files are then printed with lp using the options from LP_OPTIONS if the printer to be used is not your standard printer, you should add -d printername to the lp command [/li][li]the files are deleted after being processed. So is the mail, when fetchmail downloads it[/li][/ul]
When you have tested the script on the command line and it works, you have to make cron run this script every 2, 5 minutes or whatever you like.

With this solution, no filtering is done on the linux box. I set up the mail-account, to only accept mails from my address, to counter spam.
Sure this is not the most secure solution, but if nobody knows the mail-address and neither that there is a printer-deamon behind it, for myself I feel secure enough.
You could still expand the script to extract also a S/MIME signature attached to your mails and have that before printing.

Taraman

Link to this post 20 Jan 11

Thanks a lot I appreciate the help I will give this a try and see how I go and will let ya know


Thanks

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