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

We have an external system which happens to fail from time to time. We don't have direct access to the logs of this system, all we get are daily status mails delivered to our Inbox indicating failure or success. Now what we're trying to achieve is counting failure and success messages to somehow measure reliability.

If we would have access to the logs, this would be fairly easy using grep and wc and that kind. But all we have is a bunch of mails.

Now heres the question: Can somebody come up with way to connect to an imap-server, go to a specific folder, get all messages and count a certain string? (preferably bash, python or perl). We don't expect the exact command. Some ideas to get us started would be great.

share|improve this question
up vote 1 down vote accepted

I'd use Python and imaplib. This imaplib example connects to a mailbox and retrieves all messages. The message body is available in that loop, so you could do whatever pattern-matching you wanted to on it. You could even just (albeit wastefully) just run this script and use your familiar tools on it. (I say "albeit wastefully" because the example scripts reads all messages in the mailbox every time it runs.)

share|improve this answer
That's exactly what I was looking for. imaplib looks great. – toString Aug 21 '10 at 7:43

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.