Program: MailClient

This program is a simplistic GUI-based mail client. It uses the Swing GUI components (see Chapter 13) along with JavaMail. The program loads a Properties file (see Section 7.8) to decide what mail server to use for outgoing mail (see Section 19.3), as well as the name of a mail server for incoming mail and a Store class (see this chapter’s Introduction and Section 19.6). The main class, MailClient, is simply a JComponent with a JTabbedPane to let you switch between reading mail and sending mail.

When first started, the program behaves as a mail reader, as shown in Figure 19-2.

Mail Client in reading mode

Figure 19-2. Mail Client in reading mode

You can click on the Sending tab to make it show the Mail Compose window, shown in Figure 19-3. I am typing a message to an ISP about some SPAM I received.

Mail Client in compose mode

Figure 19-3. Mail Client in compose mode

The code is pretty simple; it uses the MailReaderBean presented earlier and a similar MailComposeBean for sending mail. Example 19-11 is the main program.

Example 19-11. MailClient.java

import com.darwinsys.util.FileProperties; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.*; /** Standalone MailClient GUI application. */ public class MailClient extends JComponent implements MailConstants { /** The quit ...

Get Java Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.