How can you read the message body into a string variable? I have been working with the javax.mail.message object and can't get access to the message body of any MultiPart email.
Sure. I simply want to get the text of the message body of the email. The content of the message. Check this code out. I have commented where I want to grab the message body text.
Date nowDate = new Date(); System.out.println(nowDate + " ### Undeliverable Process Starting ###"); String originalSender = ""; try { boolean debug = false;
folder.open(Folder.READ_WRITE); int totalMessages = folder.getMessageCount();
int newMessages = folder.getNewMessageCount();
// Attributes & Flags for all messages .. Message[] msgs = folder.getMessages();
// Use a suitable FetchProfile FetchProfile fp = new FetchProfile(); fp.add(FetchProfile.Item.ENVELOPE); fp.add(FetchProfile.Item.FLAGS); fp.add("X-Mailer"); folder.fetch(msgs, fp);
for (int i = 0; i < msgs.length; i++) { try { seen = false;
//I simply want to read the message content (message text) into a string variable here. String testcontent = (MimeMessage)msgs[i].getContent(); originalSender = getParts(msgs[i]); if(!seen) invalidateEMail(originalSender); } catch (UnsupportedEncodingException uee) { // This occurs when message is Content-Type: text/plain; charset=unicode-1-1-utf-7 nowDate = new Date(); System.out.println(nowDate + " UnsupportedEncoding occurred... Skipping this message."); } catch (Exception e) { nowDate = new Date(); System.out.println(nowDate + " " + e.toString() + " occurred... Skipping this message."); e.printStackTrace(); } }
Thanks for the link to the tutorial. The description for getting a messages content seems dubious. The getContent method does not print out anything resembling the message content that I can see. Rather it prints out some jibberish about the messages being multi part...
Tutorial Reads:
Once you have a Message to read, you can get its content with getContent() or write its content to a stream with writeTo(). The getContent() method only gets the message content, while writeTo() output includes headers.