props.put("mail.smtp.auth","true"); Session session = Session.getDefaultInstance(props,auth); //建立session Store store = session.getStore("pop3"); store.connect(host,username,password);
Folder folder = store.getFolder("INBOX"); folder.open(Folder.READ_WRITE); Message message[] = folder.getMessages();
for (int i=0,n=message.length;i { // String out_from_person = ((InternetAddress)message[i].getFrom()[0]).getPersonal();//获取邮件发信人的署名
String out_from_address = ((InternetAddress)message[i].getFrom()[0]).getAddress(); System.out.println(out_from_address);
Message forward = new MimeMessage(session); forward.setSubject("Fwd:"+message[i].getSubject()); forward.setFrom(new InternetAddress(mail_to)); forward.addRecipient(Message.RecipientType.TO,new InternetAddress(out_from_address));
BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText("Here you go with the original message: ");
Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart);
messageBodyPart = new MimeBodyPart(); messageBodyPart.setDataHandler(message[i].getDataHandler());
multipart.addBodyPart(messageBodyPart); forward.setContent(multipart);
Transport.send(forward); message[i].setFlag(Flags.Flag.DELETED,true);//DELETED,ANSWERED,DRAFT,FLAGGED,RECENT,SEEN,USER } folder.close(true); store.close();//关闭 } catch(Exception ej2) { System.out.println(ej2); }
}
void jButton5_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); message.setContent("Hello","text/plain"); message.setSubject(mail_subject); message.setText(mail_body); message.setHeader(mail_head_name,mail_head_value); message.setSentDate(new Date()); message.setFrom(new InternetAddress(mail_from,"sunxiaoming")); //to signal man |