java 发送、解析邮件实例(二)

阅读更多
package com.prase.email.eight;

/** 
 * CrazyItTest 
 * 使用JavaMail 编写接收邮件示例 
 */  
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.util.Properties;  
import javax.mail.Folder;  
import javax.mail.Message;  
import javax.mail.MessagingException;  
import javax.mail.Session;  
import javax.mail.Store;  


public class ReceiveEmailTest {  
    private static final String  PROTOCOL = "pop3";  
    private static final String  HOST = "pop3.163.com";  
    private static final String USER = "qqhechuanzhen";  
    private static final String PASS = "pass";  
    
    private static Session getMailSession(){  
        Properties props=new Properties();  
        props.put("mail.store.protocol", PROTOCOL);  
        props.put("mail.pop3.host", HOST);  
        
//      使用代理
//      props.setProperty("proxySet","true");
//	    props.setProperty("ProxyHost","10.24.5.105");
//	    props.setProperty("ProxyPort","39002"); 
        
        
        Session session=Session.getDefaultInstance(props);  
        return session;  
    }  
      
      
    private static void receiveEmail() throws MessagingException, IOException{  
        Store store=getMailSession().getStore();  
        store.connect(HOST,USER,PASS);  
          
        Folder receiveFolder=store.getFolder("inbox");//对于POP3协议此参数值只能是inbox  
        receiveFolder.open(Folder.READ_WRITE);//设置收件夹打开后的读写权限  
          
        int messageCount=receiveFolder.getMessageCount();  
        System.out.println("总共拥有邮件数:"+messageCount);  
          
        if(messageCount>0){  
            Message []messages=receiveFolder.getMessages();//得到所有的邮件  
            for(int i=0;i 
 
  • jaf-1_1_1.zip (370.7 KB)
  • 下载次数: 6
  • javamail-1.4.2.zip (2.6 MB)
  • 下载次数: 5

你可能感兴趣的:(java,email,Store,Folder)