Server Fault is a question and answer site for system and network administrators. 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

I'm writing a simple UI for the visually impaired using a speech synthesizer. I've looked all over the internet for an email client which I can script to fit these purposes but to no avail.

I believe several CLI email clients(eg MUTT) allow sending emails with command line arguments only. But I've yet to find a client that can download the emails, decode them and then dump them to a text file.

The best candidate so far seems to be mailx, but it seems like it needs quite a lot of babysitting to fit my needs.

Any suggestions for scripting-friendly email clients?

Am I missing something fundamental about MUTT?

Are there any libraries/programs that help me decode the MIME encoding used in todays emails from a maildir?

Should I just bite the bullet and write a script for mailx?

Thanks in advance.

share|improve this question
up vote 1 down vote accepted

If you really need to script something, most of today's high-level scripting languages (e.g., Python, Ruby) have good-to-excellent mail handling libraries. It's pretty easy to put something together that will feed you parts of a message.

If you're doing text-to-speech, I'm not sure what you need MIME decoding for -- MIME is typically only used for attaching binary attachments. If you're storing messages in a maildir format message store, you already have one-message-per-file, so you really don't have that much work if you just want to (a) read the message headers and (b) the first text part.

The MH suite of mail utilities may lend itself to script support if you decide to follow that route. The nmh package is available on CentOS and Ubuntu, I believe. More information here.

share|improve this answer
MIME does a lot more than attachments. read the source of any 'simple' message in your inbox and you'll see how you can't just feed that to a TTS engine – Javier Jan 11 '11 at 20:59
...and both language libraries and the nmh tools will deal with this correctly. – larsks Jan 11 '11 at 21:18
Thanks, the nmh suite seems to be exactly what I need. – Phog Jan 11 '11 at 22:01

I believe that emacs has stuff for both eyes-free usage and email and that these work well together, so you might explore that. It's scriptable, provided that you're willing to learn elisp.

Every major scripting language that supports nested data structures should have libraries to parse mailboxes or speak IMAP and to deal with MIME emails. Shell doesn't count and if you try then you're past the area where shell scripts remain maintainable. Instead, try Python/Perl/Ruby.

Python has the email package which brings a lot of the functionality into one place: plus imaplib and mailbox for your storage needs.

share|improve this answer
shell does count, since it's just a matter of calling CLI mailers with the right parameters. In fact, i'd bet it's far simpler than doing your own client in Python (something like 2-10 lines against a couple hundreds at best) – Javier Jan 11 '11 at 20:57
I'll check the python library out, it might be easier in the end for my purposes. – Phog Jan 11 '11 at 22:01
dealing safely with nested MIME parts, with multipart/alternative dealt with correctly, rather than just being treated as multipart/mixed, and so on and so on, either requires incredible complexity when handling the data, or use of nested data structures. sh doesn't cut it. ksh does. bash and zsh don't. If you want to write something which only a ksh user can possibly maintain, then sure, shell will count. – Phil P Jan 12 '11 at 1:22
Remember that email handling is fundamentally dealing with untrustworthy content, because there's no complete authenticated trail for any arbitrary email, so you have to always code to deal gracefully with what an attacker might throw at you, not just the common cases. – Phil P Jan 12 '11 at 1:24

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.