Is there a program that will allow me to connect to my mail server (IMAP) and automatically save certain new e-mails to disk? Multiple times a day I receive automated e-mail updates about pending jobs from a system that processes some information for us. The data in these e-mails is written as plain-text within the body of the message. I would like to download the newest message, parse it, and display it on my desktop. The last two parts I can manage ok - it's just the automatic downloading that is posing a challenge.

I don't use Outlook (I do use Thunderbird), but would prefer not to have the client open to make this happen. I'm currently running Win7.

link|improve this question
feedback

1 Answer

I'd approach this by writing a script. Ruby has an IMAP library, and I assume Perl and Python do as well if those are more to your tastes.

Here's a rough, untested cut in Ruby (which you'll need to install on your windows machine to use) based on an example from the IMAP docs here

  imap = Net::IMAP.new('mail.example.com')
  imap.authenticate('LOGIN', 'joe_user', 'joes_password')
  imap.examine('INBOX')
  imap.search(["NEW", "FROM", "example.from", "SUBJECT", "example subject"]).each do |message_id|
    body = imap.fetch(message_id, "BODY")[0].attr["BODY"]
    File.open('path to file', 'w') { |f| f.write(body) }
  end

You can change the parameters passed to search as you need to to identify your messages. Install ruby, save this script as a text file and set it up to run as a scheduled task every few minutes and you should get your text file with the message body.

link|improve this answer
Thanks! I don't have much programming experience beyond AutoHotKey (as much as it can be considered programming), but I might give this a shot and see what happens. – CatamountJack Feb 22 '11 at 3:15
feedback

Your Answer

 
or
required, but never shown

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