改写后的使用javamail pop3收信的javabean

作者:袖梨 2022-07-02
/*
*Author:tyfun
*DateTime:2003.01.10
*Package:com.westarsoft.mail
*/
package com.westarsoft.mail;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;
public class GetMail {
    public static String receive(String popServer, String popUser, String popPassword) {
        String mailContent = "";
        Store store = null;
        Folder folder = null;
        try {
            Properties props = System.getProperties();
            Session session = Session.getDefaultInstance(props, null);
            store = session.getStore("pop3");
            store.connect(popServer, popUser, popPassword);
            folder = store.getDefaultFolder();
            if(folder == null) throw new Exception("No default folder");
            folder = folder.getFolder("INBOX");
            if(folder == null) throw new Exception("No POP3 INBOX");
            folder.open(Folder.READ_ONLY);
            Message[] msgs = folder.getMessages();
            for(int msgNum = 0; msgNum < msgs.length; msgNum++) {

相关文章

精彩推荐