Sending Email

The shopping cart example we have reviewed allowed the user to send an email to the Webmaster for the site. This provides an opportunity to examine the use of JavaMail in a Web application. The JSP page shown next demonstrates how this is done.

The MailService (examples.javamail.MailService) class provides a simplified access to the JavaMail API. We also access the user bean from the session to allow us to fill in the values for some of the fields in the form.

This page is an HTML form and contains various input tags to gather information about the email. The from email address is provided on one of these lines. We use the value attribute for the input tag to set the value to that of the email address of the reader.

The email.jsp ...

Get J2EE™ and Beyond: Design, Develop, and Deploy World-Class Java™ Software 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.