• Post Reply Bookmark Topic Watch Topic
  • New Topic

MS Word content in Javamail Message Body  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Watch out for those deadly MS Word "smart punctuation" characters, they can really stab you in the back.

Bill
 
Sheriff
Posts: 22845
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!