www.pudn.com > srmail.rar > Receive.java
import javax.mail.*;
import javax.mail.internet.MimeMultipart;
import java.util.Properties;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
/**
* Created by IntelliJ IDEA.
* User: lgs
* Date: 2005-8-2
* Time: 16:17:34
* To change this template use File | Settings | File Templates.
*/
public class Receive {
Folder inbox;
Store store;
public Receive() {
}
public Message[] getMail(String host,String name,String password) throws Exception
{
Properties prop=new Properties();
prop.put("mail.pop3.host",host);
Session session=Session.getDefaultInstance(prop);
store=session.getStore("pop3");
store.connect(host,name,password);
inbox=store.getDefaultFolder().getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
Message[] msg=inbox.getMessages();
FetchProfile profile=new FetchProfile();
profile.add(FetchProfile.Item.ENVELOPE);
inbox.fetch(msg,profile);
return(msg);
}
private void handle(Message msg) throws Exception
{
System.out.println("邮件主题:"+msg.getSubject());
System.out.println("邮件作者:"+msg.getFrom()[0].toString());
System.out.println("发送日期:"+msg.getSentDate());
}
public void handleText(Message msg) throws Exception
{
this.handle(msg);
System.out.println("邮件内容:"+msg.getContent());
}
public void handleMultipart(Message msg) throws Exception
{
String disposition;
BodyPart part;
MimeMultipart mp=(MimeMultipart)msg.getContent();
int mpCount=mp.getCount();
for(int m=0;m