论坛首页 入门技术论坛

JAVA接收EMAIL

浏览 3562 次
锁定老帖子 主题:JAVA接收EMAIL
该帖已经被评为新手帖
作者 正文
   发表时间:2008-09-30  
下面是查看邮件信息列表的JAVA代码:
package showmailmsgm;

import javax.mail.Store;
import javax.mail.FetchProfile;
import java.util.Properties;
import javax.mail.Session;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.internet.InternetAddress;

public class Semail {
    public static void main(String[] args) {
        try {

            Properties props = new Properties();
            Session s = Session.getInstance(props);
            Store store = s.getStore("pop3");
            store.connect("pop.163.com", "bluebit_cn", "xiaohao");

            Folder folder = store.getFolder("Inbox");
            folder.open(Folder.READ_WRITE);

            FetchProfile profile = new FetchProfile();
            profile.add(FetchProfile.Item.ENVELOPE);
            Message arraymessage[] = folder.getMessages();
            folder.fetch(arraymessage, profile);

            System.out.println("收件箱的邮件数:" + arraymessage.length);
            for (int i = 0; i < arraymessage.length; i++) {
                //邮件发送者
                String from = arraymessage[i].getFrom()[0].toString();
                InternetAddress ia = new InternetAddress(from);
                System.out.println("FROM:" + ia.getPersonal() + '(' +
                                   ia.getAddress() + ')');
                //邮件标题
                System.out.println("TITLE:" + arraymessage[i].getSubject());
                //邮件大小
                System.out.println("SIZE:" + arraymessage[i].getSize());
                //邮件发送时间
                System.out.println("DATE:" + arraymessage[i].getSentDate());
            }

            folder.close(false);
            store.close();
        } catch (Exception ee) {
            ee.printStackTrace();
        }
    }
}


忘记了,再说一句,上面的代码老师是在JBuilder里写的,之前的话记得在工程属性里把JAVAMAIL相关的包加入工程里。。。
   发表时间:2008-11-08  
没用过JBuilder
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics