Package vincent.mail;
Import java.io.bufferedreader; import java.io.inputstreamReader; import java.util.properties; import javax.mail. *;
/ ** * @author vincent.yang * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates * / public class retrieveEmail {public static void main (String args [] ) throws Exception {String host = "xxxxx"; String username = "xxxxxx"; String password = "xxxxxxx"; Properties prop = new Properties (); Session session = Session.getDefaultInstance (prop, null); Store store = session. getStore ( "pop3"); store.connect (host, username, password); Folder folder = store.getFolder ( "INBOX"); folder.open (Folder.READ_ONLY); BufferedReader bReader = new BufferedReader (new InputStreamReader (System. IN); message msg [] = folder.getMess (); for (int i = 0, n = msg.Length; i } ********************************************************* ***************************** Package vincent.mail; Import java.util.properties; import javax.mail. *; import javax.mail.internet. *; / ** * @author vincent.yang * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates * / public class sendMail {public static void main (String args [] "throws exception {// the host for smtp string host =" xxxx "; // xxxx string from =" xxxxx "; string to =" xxxx "; proties prop = system.getProperties (); Prop.Put (" Mail. Stmp.host ", host); //prop.put("mail.smtp.auth","true"); session session = session.getDefaultInstance (prop, null); mimeMessage msg = new mimeMessage (session); MSG. SetFrom (New InternetDress (from); Msg.AddRecipient (Message.RecipientType.to, New Internetdress (To)); Msg.SetSubject ("Cool Man"); Msg.Settext ("Hello, I am Cool Man"); Transport Transport = session.getTransport ("SMTP"); Transport.connect (Host, "VincentYang", "56944185"); Transport.sendMessage (MSG, Msg.GetallRecipients ()); Transport .Close ();}}}