I have created a basic email client, which fetches email from the server, and displays it to the user.
I have more code than this, but this is the main body of it that prints the messages:
// retrieve the messages from the folder in an array and print it
Message[] messages = emailFolder.getMessages();
System.out.println("messages.length---" + messages.length);
for (int i = 0, n = messages.length; i < n; i++) {
String content= messages[i].getContent().toString();
Message message = messages[i];
System.out.println("---------------------------------");
System.out.println("Email Number " + (i + 1));
System.out.println("Subject: " + message.getSubject());
System.out.println("From: " + message.getFrom()[0]);
System.out.println("Text: " + message.getContent().toString());
}
However, when I run the program, I get the following output:
messages.length---4
---------------------------------
Email Number 1
Subject: Access for less secure apps has been turned on
From: Google <no-reply@accounts.google.com>
Text: javax.mail.internet.MimeMultipart@69ea3742
---------------------------------
Email Number 2
Subject: Three tips to get the most out of Gmail
From: Gmail Team <mail-noreply@google.com>
Text: javax.mail.internet.MimeMultipart@71318ec4
---------------------------------
Email Number 3
Subject: Stay more organized with Gmail's inbox
From: Gmail Team <mail-noreply@google.com>
Text: javax.mail.internet.MimeMultipart@21213b92
---------------------------------
Email Number 4
Subject: The best of Gmail, wherever you are
From: Gmail Team <mail-noreply@google.com>
Text: javax.mail.internet.MimeMultipart@a67c67e
Process finished with exit code 0
Is there any way for the actual message to be displayed, instead of the mime multipart? For example, if an email read "Hello World!" I would like it to print this after "Text:" for the relevant email message.
Any help on this would be highly appreciated!!