javaMail里有不少例子,我想试一下,怎么在我的计算机上预演?就象写的jsp程序在tomca上执行得到你所要的结果一样?请多帮忙
解决方案 »
- strust2 文件上传问题
- annot find class [com.lovo.loan.web.struts.action.CustomerAction] for bean with
- 验证登录信息,成功后无法跳转(ajax)
- 谁能推荐个基于SIMPLE协议的IM
- jsp中的java代码如何获取当前页属性值
- 求 sql 语句 处理分页技术
- 为什么这段代码没反应?想在IE和FIREFOX下鼠标经过链接后发出声音
- 一个正则表达式的问题。
- 如何计算任意两天之间的差是多少天
- jsp连接数据库,如果每页都连的话是很浪费时间,怎么办?
- 关于不同用户的登陆,session混乱的问题(在线等)
- 关于用友华表制作报表之回车换行的问题,请各位大虾救急!!!
import java.net.*;
import java.util.*;public class Pop3Monitor implements Monitor {
protected int port = 110;
protected String hostname = "pop3.sina.com.cn";
protected String username = "";//username
protected String password = "";//password
protected int timeLimit = 20000; protected PrintWriter pw;
public HashMap test() {
HashMap returnMsg = new HashMap();
try {
// Get mail messages
displayEmails(returnMsg);
} catch (Exception e) {
returnMsg.put("NetStatus", "Error");
} return returnMsg;
}
protected boolean responseIsOk() throws Exception {
String line = br.readLine();
System.out.println("< " + line);
return line.toUpperCase().startsWith("+OK");
}
protected String readLine(boolean debug) throws Exception {
String line = br.readLine(); if (debug) {
System.out.println("< " + line);
} else {
System.out.println(line);
}
return line;
}
protected void writeMsg(String msg) throws Exception {
pw.println(msg);
pw.flush();
System.out.println("> " + msg);
}
protected void closeConnection() throws Exception {
pw.flush();
pw.close();
br.close();
socket.close();
}
protected void sendQuit() throws Exception {
System.out.println("Sending QUIT");
writeMsg("QUIT");
readLine(true); System.out.println("Closing Connection");
closeConnection();
}
protected void displayEmails(HashMap returnMsg) throws Exception {
System.out.println("Opening Socket");
try {
long before = new Date().getTime();
socket = new Socket(this.hostname, this.port);
long after = new Date().getTime();
returnMsg.put("connecttime", "" + (after - before));
} catch (IOException ex) {
returnMsg.put("connection", "failed");
//throw new Exception("Invalid SMTP Address");
return;
} br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
pw = new PrintWriter(new OutputStreamWriter(socket.getOutputStream())); long before = new Date().getTime();
boolean responseOk = responseIsOk();
long after = new Date().getTime(); if (!responseOk) {
socket.close();
returnMsg.put("POP3 Service", "Abnormal");
return;
} returnMsg.put("ResponseTime", "" + (after - before)); System.out.println("Sending username");
writeMsg("USER " + this.username);
if (!responseIsOk()) {
sendQuit();
//throw new Exception("Invalid username");
returnMsg.put("UserCheck", "Not Exit");
return;
} System.out.println("Sending password");
writeMsg("PASS " + this.password);
if (!responseIsOk()) {
sendQuit();
//throw new Exception("Invalid password");
returnMsg.put("PasswordCheck", "Not Correct");
return;
} System.out.println("Checking mail");
writeMsg("STAT"); String line = readLine(true);
StringTokenizer tokens = new StringTokenizer(line, " ");
tokens.nextToken();
int messages = Integer.parseInt(tokens.nextToken());
int maxsize = Integer.parseInt(tokens.nextToken()); if (messages == 0) {
System.out.println("There are no messages.");
sendQuit();
return;
} returnMsg.put("POP3 Service","OK");
sendQuit();
}}
我已经试过好多次了,javamail的文档里也提到
目前无法实现判断是否是新邮件
谢谢,要不贴初来最好,让我们这些学习的人,好好的学习一下嘛!!!