I had this problem recently, so your research couldn't have been that good. When I say recently, I mean the last couple of days! :P
But this is what I did to read the emails (Or at least somewhat read the email. It returns a big chunk of HTML text, which isn't really always pretty in a JEditorPane
private void tableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseReleased
final java.awt.event.MouseEvent e = evt;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
if(table.getRowCount() == 0 || message == null || message.length == 0) {
// Do nothing
} else {
try {
int row = table.rowAtPoint(e.getPoint());
String subject = message[row].getSubject();
String from = InternetAddress.toString(message[row].getFrom());
StringBuilder body = new StringBuilder();
Multipart mp = (Multipart) message[row].getContent();
for(int i = 0; i < mp.getCount(); i++) {
BodyPart bp = mp.getBodyPart(i);
String disp = bp.getDisposition();
if(disp != null && (disp.equals(BodyPart.ATTACHMENT))) {
// Do something
} else {
body.append(bp.getContent());
}
}
EmailContent ec = new EmailContent(new JFrame(),true,from,subject,"<html>" + body.toString());
} catch (IOException ex) {
Logger.getLogger(MailPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (MessagingException ex) {
Logger.getLogger(MailPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
t.start();
}
I had to fill a table with messages and then when you click on a message in the table, it would show a new window with the message in it. The message array is just an array filled with Message objects. So you will obviously need a message to do this. But the part you are after is this:
StringBuilder body = new StringBuilder();
Multipart mp = (Multipart) message[row].getContent();
for(int i = 0; i < mp.getCount(); i++) {
BodyPart bp = mp.getBodyPart(i);
String disp = bp.getDisposition();
if(disp != null && (disp.equals(BodyPart.ATTACHMENT))) {
// Do something
} else {
body.append(bp.getContent());
}
}