Mail Bonding
By Al Williams
In my February 2000 column, I showed several methods that allow an applet to send email. The method I thought was most effective was to use a server-side program to send messages. This circumvented any possible difficulties with users behind firewalls, or client-side email program peculiarities.
Recently, I wanted to build a Web-based email list for a group of developers collaborating on a project. The project already has a set of Web pages, and I wanted a page on which you could select a group of people, enter a message, and mail it. Sure, most email programs let you send to groups, but then everyone has to keep their group lists current. A dedicated list server is another option, but I wanted to make a Web-based solution that uses Java.
In the February column, I mentioned that you could write Java code to open up a Simple Mail Transfer Protocol (SMTP) server and directly send mail. For an applet, this presupposes that the SMTP server is on the same server as the applet, and that the user is able to connect to it (many firewalls and ISPs block SMTP access to unknown hosts).
However, code running on the server side should have no problems opening a socket to an SMTP host. I decided to write a reusable object that could handle the SMTP part so that I could use it from Java programs, applets, or server-side Java (like a JSP page). Because this issue's focus is on collaboration, I also wanted to document the SMTP object using the Javadoc tool that generates HTML documentation for Java source code.
Inside SMTP
When you send email, you connect to an SMTP host computer on port 25.