views:

366

answers:

6

I'm planning to write an application that should handle incoming mails. Basically it will act more like a ticketing system than a webmail, so I'm only interested in receiving emails, and not sending them.

I have made a simple prototype that downloads mails and displays the text with downloadable attachments in a web page, but handling mails from Outlook and others is more complicated. I have looked at some of the open source ticketing systems out there, but most of the code is tied to the system and is hard to separate.

Is there a library that understands "rich" mail and makes this job simpler? Preferably in Python, Java, Ruby or Perl. I'm also open to suggestions for any command line mail clients that can be used for this, since the system will not receive large amounts of mail and can afford to launch external processes.

Edit:

I know about the standard mail libraries in Python and Java and can handle the mail itself, but I'm looking for a library that can help me with the "rich" emails created by Outlook/Thunderbird that contains formatting and inline images.

A: 

Python has the aptly-named email package for handling email messages.

Ignacio Vazquez-Abrams
Thanks, but it's not the actual MIME parsing that is the problem, but converting emails created by Outlook with inline images etc. to standard HTML.
MH
Unless there are ready-made libraries for this, it's next to trivial as HTML also support inlined images.
Tomasz Zielinski
+1  A: 

There are several email-handling packages in the Python standard library. I haven't worked with them very much, so I'm not sure whether they do quite what you intend, but if you haven't already I would suggest taking a look at e.g. the email package.

If you're looking for something higher-level than that, I'm sure there are third-party libraries available.

David Zaslavsky
Thanks, but those libraries mostly concentrate on decoding mails, and I'm looking for something that can handle "rich" mails created by Outlook, Thunderbird etc with inline images and formatted text.
MH
Maybe you knew this, but "rich" emails are really just MIME multipart messages. The HTML body text is one part, and each inline image is another part. If what you want to do with these messages is reasonably simple, you could probably just write a quick script to create an `email.MIMEMultipart` object from the message and do whatever you want with it.
David Zaslavsky
A: 

Java has the Javamail API that can handle MIME attachments.

Brian Agnew
A: 

PHP has the imap functions with imap_fetchstructure and imap_fetchbody u can handle all type of Emails but its kinda hard.

U can also look at http://www.squirrelmail.org/ and rip off the email view part.

Michele
A: 

For Perl, check out Ricardo Signes' Email::MIME for parsing multipart messages. Check out walk_parts, it recursively applies a callback to each part of a multipart message.

daotoad
A: 

The Zend Framework has a package called Zend_Mail that can handle multipart emails, attachments, MIME content and HTML emails

The link is here

Elliot Anderson