• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Java Mail with different content type

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to read mails from an exchange server and then save the files as rft-files. But when I read the messages from the server I lost all format infos (tables, big letters, colours, ...) from the message. It seems that I can read the messages only in the content-type "text/plain".

How can I read messages for the exchange server without loosing the format infos?

Thanks for help
oli
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sometimes email with HTML content are sent with two versions, one in plain text and one with HTML content which allows clients to switch between them. As such it is a Multipart message and the content of the first part is typically the plain text format. The HTML version of emails are usually attached as a new Part. So what you would do is
1) Cast the content of the message's content to Multipart.
2) Iterate over the Multipart's body Parts and check for their MIME type
3) When you get to HTML Part of the email, get its contents and read them.
 
Oliver Baum
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Steve,
thanks for the information. But on this case it dosn't help. Maybe I have to explain exacter.

Somebody send an e-mail to an outlook inbox. In this e-mail there are some fomat infos (tables, colour letters, ...) and you can see the informations in outlook. But when I get the mails from the inbox over java I will get a content-type for this mail text/plain. The content for this message is "instance of String". Thats all what I get. Here the code:

Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ);
Message[] message = folder.getMessages();
{
Message m = message[i];
System.out.println("ContentType: " + m.getContentType());
if(m.getContent() instanceof String)
{
// I always get instanceof String back
}

Do you know, whtats going wrong?

Thanks
Oli

 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So if you aren't getting the HTML code from the body content, and you don't have a multi part message, then it means the server is sending it to you in plain text and you will have to sort out why from the server side I think.
 
Oliver Baum
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for help. It was an configuration problem on the exchage server.

 
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic