• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading mail content

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you can cast the getContents() object to an InputStream, then read from that InputStream.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?



 
Police line, do not cross. Well, this tiny ad can go through:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic