Java Reference
In-Depth Information
String emailStatus = SendMailBean.getPasswordAndEmail();
if(emailStatus.equals("OK")){
%>
Hi <%=userName%>,<br>
Your password is being emailed to the address we have on file.
<%
}else{
%>
Sorry, <%=userName%>,<br>
Your email address is not on file.
<%
}
%>
</body>
</html>
Deployment
To deploy JavaBeans for use with JSP pages, put the class files for the beans into the appropriate
directory. For a simple Tomcat installation, the usual path is as follows:
TOMCAT/WEBAPPS/ROOT/WEB-INF/CLASSES
Recall that servlet deployment requires you to put any jar files you need into a suitable directory and to
modify Tomcat's class path in the tomcat.properties file in the Tomcat/conf directory. In this example,
the jar file is saved in the /lib directory, and Tomcat's class path is modified by adding the following
lines to the tomcat.properties file:
wrapper.classpath=lib/jdbc2_0-stdext.jar
wrapper.classpath=lib/activation.jar
wrapper.classpath=lib/mail.jar
wrapper.classpath=lib/Opta2000.jar
The store and folder classes of the core JavaMail are explained and illustrated in the next example
which illustrates how to receive e-mail messages.
Receiving E-mail Using the JavaMail API
Receiving e-mail with the JavaMail API is only a little more complicated than sending e-mail. In addition
to the JavaMail objects used to send an e-mail, receiving e-mails involves the use of the Store and
Folder objects. The following sequence of events is similar to sending an e-mail:
1. Get the default e-mail session.
2. Get the POP3 message store object.
3. Connect to the store, using the server name, mail-user name, and password.
4. Get the default folder.
5. Get the INBOX .
6. Open the INBOX and read the messages.
The process is started in much the same way as sending a message, but, after getting the session, you
connect to a Store instead of a Transport. Here's an example:
Store store = session.getStore("pop3");
store.connect(host, username, password);
Search WWH ::




Custom Search