views:

79

answers:

4

I'm embarrased of how I'm unaware of SMTP / POP3 / IMAP protocols, as much as I thought I know HTTP and TCP/IP it apears that I took email as granted, and never had to write any piece of code that will do other than sending an email via an existing SMTP server.

My task is to write an incomming email channel and I would like to hear what is the basic aproach

What I need is the ability to listen to a specific email address, and capture the body, subject and attachment of that email for further processing.

+2  A: 

An SMTP server is usually how you'd refer to an outbound mail server; it sends mail.

POP and IMAP allow you to connect to a mail server, to read the mail that's already been received.

You need the receiving/server side of SMTP, and you might benefit from reading up on MTA; mail transfer agent.

You might also be interested in reading about SMTP proxies; so, sent mail would go through your server - and could be filtered/listened to, I suppose - and then get sent further to it's actual recipient.

Dean J
IMAP can also be used to *send* mail, but it's not very popular, largely due to its complexity.
Steven Sudit
@Steven Sudit; good catch, yeah, IMAP will do it, but as you said, few folks use that.
Dean J
+2  A: 

Use the JavaMail API

JackN
This looks like a much better idea than rolling your own server.
Steven Sudit
Isn't the JavaMail API client only?
Bruno
http://www.oracle.com/technetwork/java/faq-135477.html#incservers
Bruno
+2  A: 

If you want your server to receive e-mails, it's an SMTP server that you need.

(You'll also need to make sure that the e-mail address is set up to be sent to that server, via the MX entry in the DNS.)

Note that, depending on how you want to install this service, you might not need to write an SMTP server yourself (or even use a library). Existing SMTP servers are often capable of delegating the processing of an e-mail to external applications.

You could use somelike Postfix and configure it to use pipe for that address, to send the e-mail to process to the program of your choice (including one that you develop yourself). I'm fairly sure Exim, Sendmail and other MTAs have similar features. With this sort of configuration, your application would usually need to be able to read the e-mail from the standard input (and have the ability to split/process headers and body), but that's usually much simpler that writing an MTA/SMTP server.

If you really want tighter integration with the MTA, perhaps this could be a good starting point (I've never tried it): http://james.apache.org/

Bruno
+2  A: 

I understand you want to programatically recieve mail...use subethasmtp (much lighter and easier than james etc, works very well.

raticulin