// This code is used to send a message with information html void jButton8_actionPerformed (ActionEvent e) {try {Properties props = new Properties (); Authenticator auth = new Email_Autherticator (); props.put ( "mail.smtp.host" , Host); PrOPS.PUT ("mail.smtp.auth", "true"); session session = session.getDefaultInstance (props, auth); mimeMessage message = new mimeMessage (session); // Setup mail body string htmlText =
new InternetAddress (mail_from, "sunxiaoming"); message.setFrom (address); Address toAddress = new InternetAddress (mail_to); message.addRecipient (Message.RecipientType.TO, toAddress); message.setHeader (mail_head_name, mail_head_value); message. SetSentDate (new date ()); bodypart messagebodypart = new mimebodypart (); string htmltext = "
// Create a related multipart to combine the parts MimeMultipart multipart = new MimeMultipart ( "related"); multipart.addBodyPart (messageBodyPart); // Create part for the image messageBodyPart = new MimeBodyPart (); // Fetch the image and associate to part DataSource fds = new FileDataSource (file); messageBodyPart.setDataHandler (new DataHandler (fds)); messageBodyPart.setHeader ( "Content-ID", "memememe"); // Add part to multi-part multipart.addBodyPart ( messageBodyPart); // Associate multipart with message message.setContent (multipart); Transport.send (message); System.out.println () "send ok!";} catch (Exception ex) {System.out.println ( "faild" ex);}} // for receiving the program information message with html void jButton7_actionPerformed (ActionEvent e) {try {Properties props = System.getProperties (); Authenticator auth = new Email_Autherticator (); props .put ("mail.smtp.host", host); Props.Put ("mail.smtp.auth", "true"); session session = session.getDefaultInstance (props, auth); store store = session.getStore "POP3"); store.connect (HO ST, UserName, Password); // After Connecting to the Store, You Can Get a Folder, Which Must Be Opened Before You Can Read Messages from It: Folder Folder = Store.GetFolder ("Inbox"); Folder.Open .Read_write; message message [] = folder.getMess (); for (int i = 0, n = message.Length; I // for (int i = 0, n = 1; i {string out_from_person = ((InternetAddress) ) Message [i] .GetFrom () [0]). getPersonal (); string out_from_address = (InternetAddress) message [i] .GetFrom () [0]). getAddress (); system.out.println ("from" : " Out_From_Person " / T "); System.out.println (" Address: "