Use Java to receive POP3 emails

Source: Internet
Author: User

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 ();
}

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.