MailReader1.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:1k
源码类别:
Java编程
开发平台:
Java
- //JavaMail:MailReader1.java
- //author:ZhangHongbin
- //This program is protected by copyright laws.
- //Mail Reader program.
- import java.util.*;
- import javax.mail.internet.*;
- import javax.mail.*;
- import java.io.*;
- public class MailReader1
- {
- public static void main(String[] args) throws Exception
- {
- String pop3 = "pop.21cn.com";
- String user = "bestbooks@21cn.com";
- //String user = "abc@21cn.com";
- String password = "7965117";
- //String password = "123456";
- Properties props = System.getProperties();
- Session session = Session.getInstance(props,null);
- Store store = session.getStore("pop3");
- store.connect(pop3,user,password);
- Folder folder = store.getFolder("INBOX");
- folder.open(Folder.READ_ONLY);
- Message[] msg =folder.getMessages();
- for (int i=0; i <msg.length;++i)
- {
- System.out.println("From: "+
- msg[i].getFrom()[0]);
- System.out.println("Subject: "+
- msg[i].getSubject());
- if ( ((msg[i].getFrom()[0]).toString()).equalsIgnoreCase("bestbooks@21cn.com"))
- {
- String s;
- BufferedReader in =new BufferedReader(
- new InputStreamReader(msg[i].getInputStream()));
- System.out.println("---Mail Text---");
- while((s = in.readLine())!= null)
- {
- System.out.println(s);
- }
- in.close();
- }
- }
- folder.close(false);
- store.close();
- }
- }