I am trying to get password reset link which is sent to email

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());
System.out.println("link: " + message.getDescription());


Email Number 2

Subject: Welcome to Application

From: abc xyz

Text: javax.mail.internet.MimeMultipart@185d8b6

link: null

  • How do you get your message and why do you expect getting link by calling getDescription()?
    – Alexey R.
    Sep 21, 2018 at 11:51
  • iam using this code stackoverflow.com/questions/28417037/…
    – Ash
    Sep 21, 2018 at 12:05
  • getDescription() will return mail content?
    – Ash
    Sep 21, 2018 at 12:06

2 Answers 2


When you call getContent() you get the object of javax.mail.internet.MimeMultipart class. You cannot simply take a text from there because the content might contain text, video, images, files, and so on.

You should parse your content down by parts (that might be not trivial since there might be a tree structure) and fetch data from there basing on each particular part mime type.

Check Java docs for details. The basic approach is to:

  1. Invoke getContent(). Check if returned content is a multipart. If yes,
  2. Invoke getCount() on received object to find the number of parts in your multipart
  3. Handle all BodyParts. Check class of what is returned by getContent(). If it is a MultiPart, go to step 2
  4. If it is not, call getContentType() and process the item according to the returned type.

When you get the message body, it will be a multipart message. Basically, each email server is different as to how they store their messages. You need to build a parser loops through all body parts and which for each message body part's type. And then decodes that type into something you can read.

  • can u provide one example?
    – Ash
    Sep 24, 2018 at 4:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.