先建一个html登录表单(recmain.jsp)
--------------------------------------------------------------------------------------------------------------
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>邮箱登录</title>
<link href="../images/styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<form name="form1" method="post" action="holdrec.jsp">
<table width="279" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#009900" class="black">
<tr>
<td colspan="2" bgcolor="#FFFFFF">
<div align="center">邮箱登录</div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="75" height="20">用户名:</td>
<td width="201">
<input name="username" type="text" id="username"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>密码:</td>
<td>
<input name="password" type="password" id="password"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="19">POPServer:</td>
<td><input name="popserver" type="text" id="popserver"></td>
</tr>
<tr>
<td colspan="2" bgcolor="#FFFFFF">
<div align="center">
<input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit2" value="重置">
</div></td>
</tr>
</table>
</form>
</body>
</html>
进入后的邮件列表代码(hodrec.jsp)
----------------------------------------------------------------------------------------------------------------
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.util.*,javax.mail.*"%>
<%@ page import="javax.mail.internet.*"%>
<%@ page import="javax.activation.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%request.setCharacterEncoding("gb2312");%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>收件箱</title>
</head>
<%
String popserver=request.getParameter("popserver");
String username=request.getParameter("username");
String password=request.getParameter("password");
%>
<body>
<%
Store store=null;
Folder folder=null;
Properties props =new Properties();
Session s=Session.getInstance(props);
store=s.getStore("pop3");
store.connect(popserver, username, password);
folder = store.getDefaultFolder();
folder = folder.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Message[] msgs = folder.getMessages();
for (int msgNum = 0; msgNum < msgs.length; msgNum++)
{
InternetAddress[] from=(InternetAddress[])msgs[msgNum].getFrom();
InternetAddress[] to=(InternetAddress[])msgs[msgNum].getRecipients(Message.RecipientType.TO);
%>
-----------------------------------------------------------------------------------------------
<p style="font-size:9pt;">发件人:<%=from[0].getAddress()%>,时间:<%=msgs[msgNum].getSentDate()%>,主题:<%=msgs[msgNum].getSubject()%>,大小:<%=msgs[msgNum].getSize()%>字节</p><p style="font-size:9pt;">内容:<font color=red><%=msgs[msgNum].getContent()%></font></p><br>
<%
}
folder.close(false);
store.close();
%>
</body>
</html>
(全文完)