• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

MS Word content in Javamail Message Body

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Could anyone please let me know if it is possible to read the content of a MS Word document and paste the entire content with the same format in Javamail message body? I tried to use "application/msword" as content type and other combinations, but all the time the content is sent as attachment only. Pasted the code below that I tried but didnt work as expected (may be my understanding is weak).




My requirement is to read the content and paste it in body instead of sending as an file attachment. If someone has any pointers, please do share. thanks.
 
Sheriff
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll need to use a library like Apache POI or JODConverter to either extract the content and/or turn it into HTML.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Watch out for those deadly MS Word "smart punctuation" characters, they can really stab you in the back.

Bill
 
Marshal
Posts: 28293
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
It would be possible to send a Word document as an attachment, but if you want the body of the message to contain the text, then you're going to have to take Rob Spoor's advice and extract the text properly.

However even if you did want to send the document as an attachment, your code wouldn't be satisfactory because you're converting the binary data to chars in one way and then back to bytes in a different way. You would be much better throwing away all of that code and simply passing a FileDataSource to your DataHandler.
 
We're being followed by intergalactic spies! Quick! Take this tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic