java代码:
public List<Email> receiveMail(Email email,FolderType type) throws MessagingException, IOException{
connect("imap");
folder = store.getFolder("inbox");
folder.open(Folder.READ_ONLY);
Message[] msgs = folder.getMessages();
for(Message msg : msgs){
System.out.println(msg.getContent());
}
return null;
}
配置:
mail.store.protocol=imap
mail.host=imap.sohu.com
mail.imap.auth = true

DEBUG: setDebug: JavaMail version 1.4.4
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc]
DEBUG: mail.imap.fetchsize: 16384
DEBUG: mail.imap.statuscachetimeout: 1000
DEBUG: mail.imap.appendbuffersize: -1
DEBUG: mail.imap.minidletime: 10
DEBUG: protocolConnect returning false, host=imap.sohu.com, user=HUYING, password=<null>
DEBUG: trying to connect to host "imap.sohu.com", port 143, isSSL false
* OK IMAP4 ready
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 UIDPLUS IDLE AUTH=PLAIN STARTTLS
A0 OK completed
DEBUG IMAP: AUTH: PLAIN
DEBUG: protocolConnect login, host=imap.sohu.com, [email protected], password=<non-null>
A1 AUTHENTICATE PLAIN

AGh5OTE1QHNvaHUuY29tAGFpeGluMTU4Njc4MDE0ODA=
A1 OK LOGIN succeeded
A2 CAPABILITY
* CAPABILITY IMAP4rev1 IDLE
A2 OK CAPABILITY completed
DEBUG: connection available -- size: 1
A3 EXAMINE INBOX
* 8 EXISTS
* 0 RECENT
* FLAGS (\answered \seen \flagged \deleted \draft \recent)
* OK [UIDVALIDITY 1]
A3 OK [READ-ONLY] EXAMINE successful
A4 FETCH 1 (BODYSTRUCTURE)
* 1 FETCH (BODYSTRUCTURE ((("text" "plain" ("charset" "gbk") NIL NIL "base64" 13 1) ("text" "html" ("charset" "gbk") NIL NIL "base64" 90 2) "alternative") ("image" "jpeg" ("name" "[email protected]") "<[email protected]>" NIL "base64" 484331) "related" ("type" "multipart/alternative" "boundary" "----=_NextPart_4E264D48_DF3CF948_6ADD9321") ("inline" NIL) NIL))
A4 OK FETCH completed
javax.mail.internet.MimeMultipart@1ff5ea7
A5 FETCH 2 (BODYSTRUCTURE)
* 2 FETCH (BODYSTRUCTURE (("text" "plain" ("charset" "gbk") NIL NIL "base64" 337 5) ("text" "html" ("charset" "gbk") NIL NIL "base64" 1144 16) "alternative" ("boundary" "----=_NextPart_4E268F00_086C0490_1C0AD190") ("inline" NIL) NIL))
A5 OK FETCH completed
javax.mail.internet.MimeMultipart@9f2a0b
A6 FETCH 3 (BODYSTRUCTURE)
* 3 FETCH (BODYSTRUCTURE ((("text" "plain" ("charset" "gb2312") NIL NIL "base64" 272 4) ("text" "html" ("charset" "gb2312") NIL NIL "base64" 4296 56) "alternative") ("image" "jpeg" ("name" "01.jpg") "<[email protected]>" NIL "base64" 483982) "related" ("boundary" "=====002_Dragon633484364877_=====" "type" "multipart/alternative") ("inline" NIL) NIL))
A6 OK FETCH completed
javax.mail.internet.MimeMultipart@1813fac
A7 FETCH 4 (BODYSTRUCTURE)
* 4 FETCH (BODYSTRUCTURE ((("text" "plain" ("charset" "gbk") NIL NIL "base64" 268 4) ("text" "html" ("charset" "gbk") NIL NIL "base64" 1371 19) "alternative") ("image" "jpeg" ("name" "[email protected]") "<[email protected]>" NIL "base64" 81201) "related" ("type" "multipart/alternative" "boundary" "----=_NextPart_4E2914F2_0855F2C0_0DAAB0E9") ("inline" NIL) NIL))
A7 OK FETCH completed
javax.mail.internet.MimeMultipart@7b7072
A8 FETCH 5 (BODYSTRUCTURE)
* 5 FETCH (BODYSTRUCTURE ("text" "plain" ("charset" "UTF-8") NIL NIL "base64" 1495 1 NIL ("inline" NIL) NIL))
A8 OK FETCH completed
A9 FETCH 5 (BODY[TEXT]<0.1495>)
* 5 FETCH (BODY[TEXT]<0.1495> {17}
5Y+R55Sf5aSn5bmF
)
A9 OK FETCH completed
DEBUG IMAP: IMAPProtocol noop
A10 NOOP
Exception in thread "main" java.io.IOException: No content
at com.sun.mail.imap.IMAPInputStream.fill(IMAPInputStream.java:159)
A10 OK NOOP No operation performed
at com.sun.mail.imap.IMAPInputStream.read(IMAPInputStream.java:208)
at com.sun.mail.imap.IMAPInputStream.read(IMAPInputStream.java:234)
at com.sun.mail.util.BASE64DecoderStream.getByte(BASE64DecoderStream.java:358)
at com.sun.mail.util.BASE64DecoderStream.decode(BASE64DecoderStream.java:249)
at com.sun.mail.util.BASE64DecoderStream.read(BASE64DecoderStream.java:144)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at com.sun.mail.handlers.text_plain.getContent(text_plain.java:125)
at javax.activation.DataSourceDataContentHandler.getContent(DataHandler.java:775)
at javax.activation.DataHandler.getContent(DataHandler.java:522)
at javax.mail.internet.MimeMessage.getContent(MimeMessage.java:1419)
at com.tengzhi.mail.MailUtil.receiveMail(MailUtil.java:131)
at com.tengzhi.mail.MailUtil.main(MailUtil.java:188)