少年阿宾

那些青春的岁月

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks
package org.apache.abin.mail;
import java.util.Properties;
import javax.mail.FetchProfile;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.UIDFolder;
import javax.mail.URLName;
import javax.mail.internet.MimeMessage;
import com.sun.mail.pop3.POP3Folder;
/**
*    UID速度要比messageID快好多倍,messageID下载的时候需要解析header里面头文件,所以费时
 * UID接收邮件
 * @author abin
 * 2012-2-15 下午04:33:26
 */
public class ReceiveMail {
public static void main(String args[]) throws Exception {
String host = "POP3.sohu.com";// 【POP3.163.com】
String username = "leeeee";// 【yuxia2217】
String password = "***";// 【........】
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("pop3");
store.connect(host, username, password);
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
FetchProfile profile = new FetchProfile(); 
profile.add(UIDFolder.FetchProfileItem.UID); 
profile.add(FetchProfile.Item.ENVELOPE);
if (folder instanceof POP3Folder) {
POP3Folder inbox = (POP3Folder) folder;
Message message[] = inbox.getMessages();
System.out.println("Messages's length: " + message.length);
for (int i = 0; i < message.length; i++) {
MimeMessage mimeMessage = (MimeMessage) message[i];
String uid = inbox.getUID(mimeMessage);
System.out.println("uid=" + uid);
int UnreadMessageCount = inbox.getUnreadMessageCount();
System.out.println("UnreadMessageCount="+UnreadMessageCount);
int NewMessageCount = inbox.getNewMessageCount();
System.out.println("NewMessageCount="+NewMessageCount);
URLName urlName = inbox.getURLName();
System.out.println("urlName="+urlName);
}
}
}
}







package org.apache.abin.mail;
import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Part;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.internet.MimeMessage;
import com.eastelsoft.etos.email.PraseMimeMessage;
/**
 * MessageId接收邮件
 * @author abin
 * 2012-2-16 下午01:24:30
 */
public class GetMail {
public static void main(String args[]) throws Exception {
String host = "POP3.163.com";// 【POP3.163.com】
String username = "liiiii";// 【yuxia2217】
String password = "****";// 【........】
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("pop3");
store.connect(host, username, password);
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Message message[] = folder.getMessages();
System.out.println("Messages's length: " + message.length);
for (int i = 0; i < message.length; i++) {
MimeMessage pmm=  (MimeMessage) message[i];
System.out
.println("Message " + i + " subject: " + pmm.getSubject());
System.out.println("Message " + i + " sentdate: "
+ pmm.getSentDate());
System.out.println("Message " + i + " form: " + pmm.getFrom());
System.out.println("Message" + i + " sentdate: "
+ pmm.getSentDate());
System.out.println("Message " + i + " Message-ID: "
+ pmm.getMessageID());
System.out.println("Message " + i + " reply: "
+ pmm.reply(true));
}
}
}
posted on 2012-02-16 13:28 abin 阅读(2715) 评论(1)  编辑  收藏

Feedback

# re: JavaMail 快速接收新邮件 2013-05-24 14:34 sd
ds d  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: