This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading mail content

 
harshada patil
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I wrote above code for reading mail content, but i'm failed to read the mail content as bodyPart.getContent().toString() gives object name and logger.info(bodyPart.getContent()) gives actual html content that i want. How do i get that content as string object ?
 
Paul Clapham
Sheriff
Pie
Posts: 20187
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can cast the getContents() object to an InputStream, then read from that InputStream.
 
Rob Spoor
Sheriff
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would actually prefer to use Part's getInputStream() method. getContent() could return a String if the attachment is a text file (I've seen this happen a lot) or a Message if it's an embedded (forwarded) message (don't know if that would show up as an attachment though). Both Message and BodyPart implement Part so the method is available for you.
 
harshada patil
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

No I'm getting HTML content in body, but when i'm using that contents to display as a web page, it displays without images.
 
Paul Clapham
Sheriff
Pie
Posts: 20187
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not at all surprised. The HTML code you're talking about would have to have proper links to the images, which a browser can resolve. No doubt yours doesn't.

Of course if you had posted the HTML which you had the question about, we wouldn't have to guess.
 
Rob Spoor
Sheriff
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's also possible the HTML body includes embedded images. They are <img> tags with a source that starts with "cid:", and the value after that matches the Content-ID of one of the attachments. What I've done for one project is use a Pattern / Matcher pair to find all such sources, find the matching attachments, extract these attachments to a web server's file system and then replace the source to the location of the attachment on the web server. I can't give you any more details though as my employer won't allow me to share that code.
 
harshada patil
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob. That is what exactly i want to know. Please tell me more about " extracting attachments to a web server's file system " if possible.
 
Rob Spoor
Sheriff
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, just copy the attachment contents to a file that is accessible through a web server.
 
harshada patil
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to read whole email content (message + attachments) and as there are various Content types, What is the good way to read email read email ?
 
Paul Clapham
Sheriff
Pie
Posts: 20187
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your JavaMail download you will find a "demo" folder. It contains all kinds of basic examples including one for reading the parts of an e-mail message. So start with that example and modify it to suit your requirements.
 
harshada patil
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If web server is not accessible, is there any other way to send images to application for displaying them ?
 
harshada patil
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a part of code i am using for reading email, if email contains multiple images then in some cases code is reading images in different sequence from one that appears in email, Is it possible to read images in the correct sequence ?



 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic