views:

79

answers:

3

I have java web application to which I'd like to add emailing capabilities, however, I'm unsure what is needed to accomplish this. Specifically I want my app to be able to:

  1. Send emails confirming sign-up
  2. Allow users to send emails to one another, using my app's domain i.e. [email protected]

From my research it seems I'll need a mail transfer agent (MTA) like Postfix and possibly a IMAP server like Courier; but I don't understand the need for the IMAP server.

Thanks.

A: 

For starters your server has to have mailing abilities. In linux land sendmail is usually what this will be.

Additionally, check out javaMail.

http://www.oracle.com/technetwork/java/index-jsp-139225.html

Chris
+2  A: 

You need code inside your web app to create and dispatch the email into the SMTP-world. Usually JavaMail is used for this, and you can either enclose it in your web application or (preferred) have the web container provide a correctly configured instance through JNDI. This is vendor specific.

If you do not have a SMTP-server for JavaMail to connect to (frequently this is Exchange for Windows shops), you can either get one running (ask your IT administrator) or use Google Mail or Hotmail or others if it is ok for your web application to send mail through them. It is a bit tricky to use GMail as a SMTP-server, but when set up correctly works very well.

You will need the SMTP-server, as it handles all the boring details regarding MX records and resending if the SMTP-server does graylisting, etc. etc.

Oh, and IMAP is for getting delivered mail, not sending mail. You don't need it.

Thorbjørn Ravn Andersen
Is Postfix the easiest of the open-source SMTP-servers to setup/use? Also, thanks for the clarification on the IMAP server's role; some of the examples I reviewed online made it seem like IMAP was a component of sending emails, which was confusing since IMAP stands for internet mail ACCESS protocol.
Dan
Postfix is the MTA which Ubuntu "prefers" so all the documentation refers to that. "Easy" depends on your skill set :) What platform does your web container run on, if it is some flavour of Linux, it might be very simple to get up and running
Thorbjørn Ravn Andersen
+1  A: 

If it's a Java web app, then the server part is a servlet. Given an email message sent from a client form, your server needs to send that text off as an email.

There's code in the JEE stack to do this, or you can specifically download JavaMail. This will allow your programs to act as mail clients.

Your MTA receives messages from your servlet and sends them to the users. So far so good.

But you also need a postbox, i.e. the equivalent of a mail in-box for your users. Postfix, QMail and others offer a basic "flat" mailbox model, where mail is simply stored until the client picks it up, and then (usually) deleted. Access is via POP3. IMAP offers a lot more organizational capability, i.e. the ability to specify hierarchies of nested mailboxes, to transfer mails between them and so on. You probably won't want to create a GUI front end to all that complexity, so I'd guess you don't really need an IMAP server. You do, however, want a relatively simple POP3 server to allow your servlet to access the mailboxes via TCP/IP. This is usually part of the "standard" email server packages.

To have your own domain known to the world, you need access to the MX records of your DNS service, i.e. you have to set up one or two of your hosts, on an Internet-facing address, to be your post office.

Finally, if you want to save yourself a lot of trouble, be very careful in configuring your MTA (SMTP server) such that there is no chance for it being used as an open relay. i.e. it should not be possible for your users to send mail to the outside world in general (or hackers will find a way to abuse your Web interface to do this), and mail from the Internet should not reach your users. Most importantly, there should be no way for mail from the Internet to be forwarded to someplace else in the Internet. Find an open relay testing service (they're free) on the 'net and get one to run a test on your configuration once you think you're done.

EDIT:

Looking at Thorbjorn's answer, I realized you probably don't want your users receiving their mail through your app; they probably already have email providers and accounts of their own. In that case, you don't need to worry about inbox capability or a POP3 server. You could consider offering full email services at your domain but that's a very thankless job and if you have any choice, leave that dirty work to GMail, Yahoo, Hotmail and their ilk. Whatever service you provide will never please your customers enough, and you'll be fighting spam and other crime every day.

Carl Smotricz
Big plus for security concerns. Think twice, no triple, before doing this.
BalusC
A simple solution to your own SMTP server, would be a virtual Ubuntu 10.04 server instance (running inside vmware, virtualbox, parallels, virtual pc) with postfix installed and configured.
Thorbjørn Ravn Andersen
At this point, I only want to provider my app users with the ability to send emails. I agree that offering full email services would probably be a thankless job with minimal additional (if any) benefits. Thanks for the detailed explanation and the heads-up on the open relay testing service; it was very helpful. I will certainly look further into relay testing.
Dan