67,515
社区成员
发帖
与我相关
我的任务
分享
public class MailReceiverTest {
public static void main(String[] args) throws Exception {
String pop3Server = "mail.xxxxxx.com";
String protocol = "pop3";
String user = "xxx@xxxxxx.com";
String pwd = "xxxxxx";
Properties props = new Properties();
props.setProperty("mail.store.protocol", protocol);
props.setProperty("mail.pop3.host", pop3Server);
Session session = Session.getInstance(props);
session.setDebug(true);
Store store = session.getStore();
store.connect(pop3Server, user, pwd);
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
try {
Message [] messages = folder.getMessages();
// 此处 mailCounts 数量为 2,与我收件箱中一致,正确
int mailCounts = messages.length;
for(int i = 0; i < mailCounts; i++) {
String subject = messages[i].getSubject(); // subject 为 null,为何 ?
String from = (messages[i].getFrom()[0]).toString();
System.out.println("第 " + (i+1) + "封邮件的主题:" + subject);
System.out.println("第 " + (i+1) + "封邮件的发件人地址:" + from);
}
} finally {
folder.close(false);
store.close();
}
}
}
Loading javamail.default.providers from jar:file:/C:/Users/tianxiang/.m2/repository/javax/mail/mail/1.4.7/mail-1.4.7.jar!/META-INF/javamail.default.providers
DEBUG: loading new provider protocol=imap, className=com.sun.mail.imap.IMAPStore, vendor=Oracle, version=null
DEBUG: loading new provider protocol=imaps, className=com.sun.mail.imap.IMAPSSLStore, vendor=Oracle, version=null
DEBUG: loading new provider protocol=smtp, className=com.sun.mail.smtp.SMTPTransport, vendor=Oracle, version=null
DEBUG: loading new provider protocol=smtps, className=com.sun.mail.smtp.SMTPSSLTransport, vendor=Oracle, version=null
DEBUG: loading new provider protocol=pop3, className=com.sun.mail.pop3.POP3Store, vendor=Oracle, version=null
DEBUG: loading new provider protocol=pop3s, className=com.sun.mail.pop3.POP3SSLStore, vendor=Oracle, version=null
DEBUG: getProvider() returning provider protocol=pop3; type=javax.mail.Provider$Type@a54f742; class=com.sun.mail.pop3.POP3Store; vendor=Oracle
DEBUG POP3: mail.pop3.rsetbeforequit: false
DEBUG POP3: mail.pop3.disabletop: false
DEBUG POP3: mail.pop3.forgettopheaders: false
DEBUG POP3: mail.pop3.cachewriteto: false
DEBUG POP3: mail.pop3.filecache.enable: false
DEBUG POP3: mail.pop3.keepmessagecontent: false
DEBUG POP3: mail.pop3.starttls.enable: false
DEBUG POP3: mail.pop3.starttls.required: false
DEBUG POP3: mail.pop3.apop.enable: false
DEBUG POP3: mail.pop3.disablecapa: false
DEBUG POP3: connecting to host "mail.sinotrans-mingzhou.com", port 110, isSSL false
+OK sinotrans-mingzhou.com POP3 MDaemon 14.0.3 ready <MDAEMON-F201506241428.AA2816603MD4765@sinotrans-mingzhou.com>
CAPA
+OK Capability list follows
TOP
USER
UIDL
.
DEBUG POP3: authentication command trace suppressed
DEBUG POP3: authentication command succeeded
STAT
+OK 0 0
QUIT
+OK stx@sinotrans-mingzhou.com sinotrans-mingzhou.com POP3 Server signing off (mailbox empty)