I'm new to bash scripting and I've read tons of manuals for programs like mutt, procmail, ripmime, and such and still have no clue how to this script or even use these programms properly.

If someone could help me out with that, that'd be great.

  • and what exactly do you want to achieve?
    – Bart
    Aug 24, 2019 at 10:00
  • I'm trying to write a script that checks my mailbox, grabs attachments and then moves them to some directory
    – Gneiss
    Aug 24, 2019 at 10:10
  • You could use a combination of fetchmail (to dl the mail), procmail (to decide what to do with it), and ripmime (to extract the attachments) for that.
    – cas
    Aug 24, 2019 at 11:07

1 Answer 1


If you want to download mail (e.g. from a remote imap or pop mail server), you need to use a program such as fetchmail or getmail. Both of these are available as packages for Ubuntu, so can be installed with apt.

These programs can be configured to connect to your remote mail server(s), authenticate with your username and password, download mail and either store it in a specified directory, or pipe it into an external program such as procmail for further processing.

As for the programs you mentioned:

  • mutt is a full-featured mail client or Mail User Agent (MUA). It can be configured to connect to a remote pop or imap mail server (allowing you to read and send mail, or save specific messages to local storage), but isn't really suitable for automated mail download & processing.

  • procmail is a Mail Delivery Agent (MDA). It is used to deliver mail to particular files, directories, or even forward them to other email addresses depending on matching rules in a .procmailrc file.

    procmail is mostly used with Mail Transfer Agents (like postfix or exim or sendmail etc) but is often used with programs like fetchmail - fetchmail does the fetching, and procmail rules examine the headers and/or the body of each message to decide whether to save each message to a file, pipe it to one or more other programs (e.g. ripmime), and/or forward it to another address.

  • ripmime is a tool used to extract MIME attachments from a message you have already read. you can use it on files containing saved messages, or pipe messages to it from an MUA like mutt.

  • Thanks for the full reply. The thing is that I don't know how to write the script itself to automate these procedures
    – Gneiss
    Aug 26, 2019 at 1:11
  • That would require multiple questions and answers. Start by looking at the docs for fetchmail (or getmail). Ttry to get it to download your mail and save each message to an mbox or maildir file. Ask questions here about any specific problems you're having. Then figure out how to get fetchmail or getmail to pipe incoming mail into procmail (again, ask specific questions here as needed). finally, ask about how to write procmail rules to a) match specific messages, and b) use ripmime or whatever to extract attachments. i.e. "break a large task down into smaller ones"
    – cas
    Aug 26, 2019 at 1:57
  • Okay, I will try. Thank you for your advices and time
    – Gneiss
    Aug 26, 2019 at 2:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .