Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a preferably CLI based program I can use to regularly (through cron for example) use to check a mailbox, and download the attachments into a folder?

I have a mailbox called photos@doamin.com, I would like to periodically poll the inbox for new emails via POP or IMAP, and grab the attachments to any new emails (they will be photos) and download them to a local folder.

What CLI email utils can do this?

share|improve this question
I use fetchmail and maildrop as a cronjob, but it might not be what you want – warl0ck Oct 27 '12 at 11:36
The basic idea is to download the mails using fetchmail or similar, and then extract the attachments with munpack. (I won't develop on this, so I'll just leave this comment and no answer.) – angus Oct 27 '12 at 15:58
up vote 4 down vote accepted

Fetchmail is the de facto standard program to retrieve mail over POP or IMAP automatically. You can inject email in the local email system for delivery, or have fetchmail invoke a mail delivery agent such as procmail or maildrop directly.

To extract and possibly strip the attachments, you can use any of the several MIME manipulation tools, such as mpack, metamail.

Here's a simple example using procmail (mda procmail in ~/.fetchmailrc) which saves image attachments and still delivers the mail normally — put this in your ~/.procmailrc:

* ^To: photos@doamin.com
| munpack -q -C "$PHOTO_DROP_DIR"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.