}
package demo2;
import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Store;
public class JavaMailDemo2 {
public static void main(String[] args) throws Exception{
Properties props=new Properties();
props.setProperty("mail.store.protocol", "pop3");
props.setProperty("mail.pop3.host", "pop3.sohu.com");
Session session=Session.getInstance(props);
session.setDebug(true);
Store store=session.getStore();
store.connect("pop3.sohu.com","z_p_u","***********");
Folder folder=store.getFolder("inbox");
folder.open(Folder.READ_ONLY);
System.out.println(folder.getMessageCount()+"-----------");
Message msg[]=folder.getMessages();
for(Message msgg:msg)
{
Multipart mp=(Multipart) msgg.getContent();
for(int i=0;i<mp.getCount();i++)
{
System.out.println(mp.getBodyPart(i).getContent());
System.out.println(mp.getBodyPart(i).getContentType());
}
}
}
}
原文地址:http://blog.csdn.net/u013516966/article/details/42538847