In the past, I spent almost a summer vacation playing net to implement a POP3 mail receiving component.
, So the memory is particularly profound ~ Haha
I have no intention of seeing a subproject commons under Apache today. Its purpose is to develop some commonly used component packages.
For example, dbpool or something.
For more information, see here.
Http://jakarta.apache.org/commons/index.html
There is a net package that contains components that support the following protocols:
Supported Protocols are:
- FTP
- NNTP
- SMTP
- POP3
- Telnet
- TFTP
- Finger
- Whois
- REXEC/RCMD/Rlogin
- Time (rdate) and daytime
- Echo
- Discard
- NTP/SNTP
Haha! Really strong ~~
This includes the POP3 mail receiving protocol.
So we started work !~
First, append the package to the Eclipse project.
The next package can be found here
Http://mirror.vmmatrix.net/apache/jakarta/commons/net/binaries/commons-net-1.4.1.zip
Create a demo. Java class and click the following code ~ Simple. Of course, you need to re-code your region. Otherwise, the Chinese text is displayed
Package test;
Import java. Io. reader;
Import java. Io. bufferedreader;
Import org.apache.commons.net. pop3.pop3client;
Import org.apache.commons.net. pop3.pop3messageinfo;
Public class demo {
Public static void main (string [] ARGs ){
Pop3client POP3 = new pop3client ();
Try {
Pop3.setdefaport port (110 );
Pop3.connect ("pop.qq.com ");
// I tested QQ mail ~
// Enter your QQ number as the fuel tank name, QQ password as the mailbox Password
If (pop3.login ("Fuel Tank name", "email password ")){
Pop3messageinfo [] p3m = pop3.listmessages ();
System. Out. println ("You have a total of" + p3m. Length + "mails ");
For (pop3messageinfo OBJ: p3m ){
Int id = obj. Number; // obtain the unique encoding of a letter on the server.
Reader Red = pop3.retrievemessage (ID );
Bufferedreader BR = new bufferedreader (red );
While (Br. Readline ()! = NULL ){
System. Out. println (Br. Readline ());
}
}
}
Pop3.logout ();
Pop3.disconnect ();
} Catch (exception e ){
// Todo auto-generated Catch Block
System. Out. println ("failed ");
E. printstacktrace ();
}
}
}