• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Mail... Message.getContent().. can't get Content!

 
Anton Pechsherov
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Show INBOX for urkanah@pop.mail.ru
From:=?KOI8-R?B?68nS2sHeIPPB0M/H?= <urkanah@gmail.com>
Subject: test
Content: javax.mail.internet.MimeMultipart@787171

I can not get Content of my test message, how i can get it? Sorry of my english
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The toString method of the MimeMultipart class doesn't return anything useful, as you can see. You'll need to iterate over all MIME parts using the getCount() and getBodyPart(int) methods. That'll provide you with MimeBodyPart objects that have various methods to give you access to their content.
 
Anton Pechsherov
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have an exammple?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like this:

If you read the javadocs of those classes you'll probably find other methods that are of interest.
 
Anton Pechsherov
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Type mismatch: cannot convert from BodyPart to MimeBodyPart

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's why I said "Something like..."; I didn't want to do all your work :-)

Do you know how to find out the exact class of an arbitrary Java object? And are you familiar with the concept of casting?
 
Anton Pechsherov
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:That's why I said "Something like..."; I didn't want to do all your work :-)

Do you know how to find out the exact class of an arbitrary Java object? And are you familiar with the concept of casting?

Ok... thank you.. i ll try all i can find )))
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just remove the "Mime" part from Ulf's code. You should program against the interfaces and abstract classes anyway. Sure, getContent() returns a MimeMultipart now, but in the future that may change to some other Multipart implementation.

And don't forget to check the type of getContent() - it could very well be a String for plain text emails without attachments. So:
 
Anton Pechsherov
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Just remove the "Mime" part from Ulf's code. You should program against the interfaces and abstract classes anyway. Sure, getContent() returns a MimeMultipart now, but in the future that may change to some other Multipart implementation.

And don't forget to check the type of getContent() - it could very well be a String for plain text emails without attachments. So:

Thanks... this is
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic