Chapter 8. JavaMail

In the previous chapter, we upgraded the JAW Motors application by adding the ability to run a credit check on a customer using JMS messaging and an MDB. We didn’t want to make the user wait a long time for the credit verification to complete, so we deferred this process to the background. As you’ll recall, the CreditCheckProcessor MDB received the credit check message, invoked a simulated external credit verification service, and printed the result. But this wasn’t completely satisfying because the user on the web site didn’t know the final result of the credit verification process. In this chapter, we’ll upgrade the MDB to use the JavaMail API for sending an email notification message to the user. Along the way we’ll show how to deploy and configure JavaMail on JBoss.

JavaMail 1.2 is a J2EE API that enables Java programs to send and receive email messages. With JavaMail, you can send text or HTML messages, and you have the option to include Multipurpose Internet Mail Extensions (MIME) attachments. To keep things simple, we’ll send text messages without attachments.

Let’s start by briefly reviewing where we left off in the last chapter.

Running a Credit Check

If you’ll recall, we added a “Run Credit Check” link to the JAW Motors homepage as shown in Figure 8-1.

JAW Motors homepage
Figure 8-1. JAW Motors homepage

When the user clicks on the “Run Credit Check” link, the Controller routes ...

Get JBoss at Work: A Practical Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.