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

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
LVL 1
s1m0neAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Andrew DoadesIT TechnicianCommented:
I don't know and have not done much with receiving email with action mailer, but this article on the rails wiki looks good

http://wiki.rubyonrails.org/rails/pages/HowToReceiveEmailsWithActionMailer

Hope this helps!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Andrew DoadesIT TechnicianCommented:
the above link also covers download, decoding attachments!
0
LocoTechCJCommented:
I would suggest looking at TMail for Ruby.  It is a powerful and somewhat simple library.

http://tmail.rubyforge.org/

--LTCJ
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Andrew DoadesIT TechnicianCommented:
0
s1m0neAuthor Commented:
doades,

Thanks. Those links *would* be promising if they did not require Windows-only proprietary software. If you find anything similar that is open and runs on Linux, please let me know. I am still interested in a solution.
0
Andrew DoadesIT TechnicianCommented:
Ah, sorry about that!
I will have a look around for you!
0
s1m0neAuthor Commented:
This is really old, but I could still use help on this.

If there are any new insights, I would be glad to hear them.

Otherwise, I may be required to close this question.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Ruby

From novice to tech pro — start learning today.