wood burning stoves 2.0*
The moose likes Other JSE/JEE APIs and the fly likes Java Mail... Message.getContent().. can't get Content! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Java Mail... Message.getContent().. can Watch "Java Mail... Message.getContent().. can New topic
Author

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

Anton Pechsherov
Greenhorn

Joined: Sep 09, 2008
Posts: 26


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


I make different errors when writing posts...because i don't speak English...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41102
    
  45
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.


Ping & DNS - my free Android networking tools app
Anton Pechsherov
Greenhorn

Joined: Sep 09, 2008
Posts: 26
Do you have an exammple?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41102
    
  45
Something like this:

If you read the javadocs of those classes you'll probably find other methods that are of interest.
Anton Pechsherov
Greenhorn

Joined: Sep 09, 2008
Posts: 26
Type mismatch: cannot convert from BodyPart to MimeBodyPart

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41102
    
  45
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

Joined: Sep 09, 2008
Posts: 26
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

Joined: Oct 27, 2005
Posts: 19651
    
  18

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Anton Pechsherov
Greenhorn

Joined: Sep 09, 2008
Posts: 26
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Mail... Message.getContent().. can't get Content!
 
Similar Threads
How to parse the content(mail body) of email using java mail API
JavaMail works on one server, but not another
java mail throws
JavaMail response -1 from Server : {
JavaMail: Help with sending e-mails