views:

20

answers:

1

I recently ran across this problem while trying to implement a service that has really simple data entry. Basically what I want to do is to be able to send an email to a special email address and the mail should be parsed and then the data is to be processed by my application. Now I can find hundreds of tutorials on how to send mails from J2EE, but never on how to receive them. Is there a simple way to process incoming mails using some form of MailServlet.

Regards, Christian

+3  A: 

Receiving mails with a servlet is like eating soup with a knife.

To receive mails, you need to have a mail server active; usually running either (or possibly both) SMTP and/or IMAP. This is the software that will end up accepting your mails from outside.

Under Unix systems, you generally the mail server push received mails into a Mail Transfer Agent (MTA) that does something mundane like writing your received mails into your mailbox, which may be either a file or a directory. However, you can configure this process to alternatively pipe (in a shell) the mail into a program of your choice. That program could be a C or Java program which then accesses your Web server doing a POST with the contents of the mail, and then you could process your incoming mail on your Web server.

But it would be much easier to process the mail in a program that is not your Web app server, perhaps an application that simply writes the mail's contents to a database, perhaps after some processing.


If you're alreading doing a lot of stuff with Java, you may find it most convenient to use and maybe modify a, no the Java mail server: It's called James. It may be easier to build mail-lets for James than to bolt some other processing on to a "standard" C mail server. However, I haven't heard much from James lately, so I don't know just how good a mail server it is, how actively it's developed, etc. You'd have to do some exploring on your own (or ask more questions here).

Carl Smotricz
+1 For the soup and the knife :) (still rofling behind my screen). And for James also.
Pascal Thivent
Well I got the idea after reading the AppEngine documentation which allows developers to simply register a normal HttpServlet and then passes incoming mails to it. Would have been nice, but if that's the way it is I'll have to write yet another wrapper to pipe the mails into.
cdecker
Ah, I understand. I played with GAE a bit but didn't notice the mail-to-servlet thingie. Well, given that GAE allows nothing BUT Web Apps, I guess they had to provide this.
Carl Smotricz