Welcome to the Linux Foundation Forum!

auto print email attachments as they arrive

auto print email attachments as they arrive

why is this so hard to find information on? I used a windows program in my windows computer it worked great untill the 30 days was up

I have tried "Claws mail" it seems to have actions and commands but I am way to nuibie to get how it can be done

I am open to any suggestions

the reason I want this is going to be handy to many and I tell you why - I have a Voip phone and receive all my incoming faxes to my Email as a pdf attachment. I cant be checking my email ever 5 minutes its just impractical.

any help or ideas?

Comments

  • marc
    marc Posts: 647
    Shouldn't be that hard with a little scrip. I'm no expert though :(

    Maybe someone else can make a little script to send the attachments to your printer (although for that I guess we'll need more information about your system...)
  • Goineasy9
    Goineasy9 Posts: 1,116
    Gmail, for example, can filter emails with just the "has an attachment" option checked. A cron job that prints everything in a certain folder can print the filtered emails after they're vectored to that folder. I find it inherently dangerous to print out all attachments, but, it all depends on how your filters work. It may be easier than you think.
  • I have been using linux mint - I have an email address that only gets messages sent by my Faxmail so every email has a PDF attachment - how do I make a cron job?
  • mfillpot
    mfillpot Posts: 2,180
    I do not have any guidance to offer, but the like the idea of this task. I have forwarded info about this request to a knowledgeable group I know and hopefully someone will come offer guidance.
  • mfillpot
    mfillpot Posts: 2,180
    My inquiry to outside users has yielded responses and confirmation that it has been done. I am currently awaiting a confirmation from the responders that I can repost their responses.
  • mfillpot
    mfillpot Posts: 2,180
    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:.*[email protected]
    | "/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.
  • 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
  • marc
    marc Posts: 647
    Must it be with claws email or can you use another mail client?
  • 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
  • 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
  • Thanks a lot I appreciate the help I will give this a try and see how I go and will let ya know


    Thanks
  • 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.
  • 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 ?
  • I fear, that is not my cup of tea...

Categories

Upcoming Training