Java Reference
In-Depth Information
MimeMessage message = new MimeMessage(session);
try{
// Set the sender and recipient addresses
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,new
InternetAddress(email));
// Set the subject
message.setSubject("Password Reminder");
// Set the message content
message.setText("Hi "+memberName+",\nYour password is: "+
password+"\nregards - "+from);
// Send it
Transport.send(message);
}catch(AddressException ae){
}catch(MessagingException me){
}
}
}
The SQL query in this example is fairly efficient, since the Login Table is indexed by UserName and the
ContactInfo Table is indexed by MemberID. However, you can make the query faster by forwarding the
MemberID from the previous page, so that you need only query the ContactInfo Table.
A JSP Page for Use with the SendMailBean
Using the SendMailBean requires a JSP page to set the UserName argument and to call the method
SendMailBean.getPasswordAndEmail() to query the database and send the e-mail. The JSP
page required to use the SendMailBean looks something like the example in Listing 16-2 .
Listing 16-2: A JSP page for use with the SendMailBean
<html>
<head>
<title>Email Password</title>
</head>
<body>
<%@ page language="java"%>
<jsp:useBean id="SendMailBean" scope="application"
class="JavaDatabaseBible.ch12.SendMailBean"/>
<jsp:setProperty name="SendMailBean" property="*"/>
<%
String userName = request.getParameter("username");
Search WWH ::




Custom Search