Advertisement

11.06.2008 at 03:40PM PST, ID: 23883764 | Points: 500
[x]
Attachment Details

Automatically Downloading and Saving E-Mail Attachments with Ruby / ActionMailer

Tags:

Ruby, ActionMailer, Linux

Hello,

I would like to develop a Ruby script, using ActionMailer (or something similar), that logs into a particular e-mail account (on a remote server), checks for new messages, and downloads the messages, saving any attachments (usually .jpg or .pdf) to a subdirectory based on the date the e-mail was sent (local time) and writing relevant header information and any body text to a log file, named according to the date, time, and sender.

So, for example, if john@mycompany.com sent an e-mail to the account in question, two days ago, at 15:34:07 EST, with the attachments 1001.jpg, 1002, jpg, and 1003.jpg, the script when run will create (if it does not yet exist) a directory /path/to/mail/2008/Nov/04, saving the three attachments, and creating a log file named something like 2008-Nov-04-153407-john.log.

This script will be run on a Linux server, and eventually will be scheduled with cron.

I am familiar with Ruby, though I am by no means an expert. ActionMailer, however, I had not used at all until just last week, and so far, I have used it only for sending e-mail.

Initially, I'd like to leave the e-mails on the server, but I'd like to have to option of removing any e-mail older than x number of days.

Any help on this will be greatly appreciated.

Thanks in advance,

s1m0ne
 
Expert Comment by doades:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by doades:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by LocoTechCJ:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by doades:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by s1m0ne:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by doades:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
20081119-EE-VQP-45 / EE_QW_2_20070628