JavaMail receives emails. javamail receives emails.
A simple example is to collect all emails and output them on the console.
Package cn. jmail. test; import java. io. *; import java. util. *; import javax. mail. *; public class MailReceives {public static void main (String [] args) {String pop3Server = "pop3.163.com"; String protocol = "pop3"; String username = "xxxx "; string password = "xxxx"; Properties prop = new Properties (); prop. setProperty ("mail. store. protocol ", protocol); prop. setProperty ("mail. pop3.host ", pop3Server); Ses Sion mailSession = Session. getDefaultInstance (prop, null); mailSession. setDebug (false); try {Store store = mailSession. getStore (protocol); // log on to verify the store. connect (pop3Server, username, password); // obtain the email account Folder folder = store. getFolder ("inbox"); // set the access permission folder. open (Folder. READ_WRITE); // get all mail Message [] messages = folder. getMessages (); for (int I = 0; I <messages. length; I ++) {// subject String subject = messa Ges [I]. getSubject (); // The sender address String from = messages [I]. getFrom () [0]. toString (); System. out. println ("no." + (I + 1) + "the subject of the email is:" + subject + "\ t. The sender address is:" + from); System. out. println ("do you want to read this email (y/n )? "); BufferedReader bufferedReader = new BufferedReader (new InputStreamReader (System. in); String input = bufferedReader. readLine (); if ("y ". equals (input. toLowerCase () {messages [I]. writeTo (System. out) ;}} folder. close (false); store. close ();} catch (NoSuchProviderException e) {e. printStackTrace ();} catch (MessagingException e) {e. printStackTrace ();} catch (IOException e) {e. printStackTrace ();}}}
Mail. jar and activation. jar http://pan.baidu.com/s/1qW7MaS0
Here, I will share with you a book about javamail, Java mail development details. You can Baidu on your own.